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 2000 Forums
 Transact-SQL (2000)
 Count Function

Author  Topic 

1sqlover
Yak Posting Veteran

56 Posts

Posted - 2006-10-12 : 18:16:16
I would like to perform the following query:

1. Count the number of times a number (ProductID) is in a certain row.
2. Display the top 25 numbers that were grouped together by (1) or ProductID.

Fields
ProductID, ProductName, CustomerName, Qty

Thanks

1sqlover
Yak Posting Veteran

56 Posts

Posted - 2006-10-12 : 18:21:55
I guess I should have made myself clear. I want to not only count the number of times PRODUCTID (Distinct) appears but include it with outher information.

SELECT COUNT(DISTINCT ProductID), ProductName FROM Table1

epoh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-12 : 20:05:07
[code]
select ProductID, ProductName, count(*)
from Table1
group by ProductID, ProductName
[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-12 : 21:13:59
If you learn SQL, you can do it yourself

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

1sqlover
Yak Posting Veteran

56 Posts

Posted - 2006-10-12 : 21:19:38
Khtan, thank you for the tip.

madhivanan, thanks for the links.
Go to Top of Page
   

- Advertisement -