Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Select Count

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2011-08-25 : 07:59:33
Hi,

I have a query here.

SELECT Product_ID From Products

Eg. The results I get is as below:

Product_ID
A
A
B
C
D

How can I count how many times the product appear in the query? The result I want to get is as below:
Product_ID Times
A 2
B 1
C 1

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-25 : 08:03:00
[code]
SELECT Product_ID
,COUNT(*) as Times
FROM Products
GROUP BY Product_ID
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -