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)
 Multiple Having Clauses Is there such a thing

Author  Topic 

omega1983
Starting Member

40 Posts

Posted - 2009-10-02 : 11:13:13
Is there such a thing as multiple having clause in sql 2005
Here is my code
select count(id),batch, class, date
from Gifts
group by batch,class,date
having count(batch)>1

my desired output is
batch class
2322 m
2322 b

In other word I want the gift batch to show only if there is more than one class. is there such a thing as
having count(batch)>1 and having count(class)>1?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-02 : 11:18:33
do you mean this?

SELECT t.*
FROM Gifts t
JOIN (select batch
from Gifts
group by batch
having count(class)>1)t1
ON t1.batch=t.batch
Go to Top of Page

mivey4
Yak Posting Veteran

66 Posts

Posted - 2009-10-02 : 11:18:39
Yes. The syntax would be:

select count(id),batch, class, date
from Gifts
group by batch,class,date
having (count(batch)>1
and count(class)>1)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-02 : 11:18:57
you can use AND operator

having count(batch) > 1
AND count(class) > 1



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-02 : 11:19:56
Slow again. And this time double


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -