2016年5月6日 星期五

MSSQL How to COUNT by categories

Find the Count of Product A, Product B, Product C

In product_table

product
-----------------------------------
product_a
product_b
product_a
product_c

SELECT product, COUNT(*) AS Cnt
FROM product_table
GROUP BY product

product              Cnt
-----------------------------------
product_a           2
product_b           1
product_c           3