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 2005 Forums
 Transact-SQL (2005)
 show customers with 1 product

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-02-15 : 06:06:52
hi,
how can I show my customers that only have 1 product.


I thought I could do this :

Select personid from product
group by personid
having count(personid) = 1




harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-15 : 06:08:35
[code]Select PersonID from Product
group by PersonID
having min(ProductID) = Max(ProductID)[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-02-15 : 06:14:07
thank you,
but how can I then do cutomers with 2 products.. or 3 products, etc ?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-15 : 06:21:19
Select PersonID from Product
group by PersonID
having count(distinct ProductID) = 2..3..4



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-02-15 : 06:41:24
thank you, Thats perfect.
Go to Top of Page
   

- Advertisement -