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 2012 Forums
 Transact-SQL (2012)
 Counting with filters

Author  Topic 

dmcdonnell
Starting Member

2 Posts

Posted - 2013-10-21 : 13:47:02
So i have a database where I need to count the occurances of part numbers in warehouses

so i may have

PartNo___________Warehouse
906______________T1011
408______________T1080
906______________T1080
906______________T1011

and i need returned

PartNo___________Warehouse___________Occurence
906______________T1011_______________2
408______________T1080_______________1
906______________T1080_______________1

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2013-10-21 : 14:03:53
select partno, warehouse, count(*) as occurence
from yourtable
group by partno, warehouse

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-21 : 14:03:59
[code]SELECT PartNo, Warehouse, COUNT(*) As Occurence
FROM YourTable
GROUP BY PartNo, Warehoue;[/code]
Go to Top of Page
   

- Advertisement -