September 26, 2007 at 3:56 pm
I can do a select count from a table, no problem:
select BUSINESS_UNIT, ASSET_ID, count(*)
from FS.dbo.PS_AID
group by BUSINESS_UNIT, ASSET_ID
order by BUSINESS_UNIT, ASSET_ID, count (*)
What I cannot come up with is a way to qualify the select for rows whose count is less than 4.
select BUSINESS_UNIT, ASSET_ID, count(*)
from FS.dbo.PS_AID
---- having count(*) < 4 --- this doesn't cut it
group by BUSINESS_UNIT, ASSET_ID
order by BUSINESS_UNIT, ASSET_ID, count (*)
I cannot find direction in the Help files, so I am posting here.
TIA,
jej1216
September 26, 2007 at 4:01 pm
your having clause just needs move after the group by statement and needs to be before the order by statement
September 26, 2007 at 4:05 pm
To quote Homer Simpson, 'Doh!'
Thanks, that's what I needed.
December 31, 2010 at 7:31 am
select * From Table
group by ....
having count(?)>(select count(?) from Table1)
:w00t:
December 31, 2010 at 7:32 am
select * from table
group by ...
having count(*)>4
December 31, 2010 at 8:03 am
Please note: 3 year old thread.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 31, 2010 at 11:54 pm
GilaMonster (12/31/2010)
Please note: 3 year old thread.
Heh... and a seriously wrong answer to boot!
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply