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
 SQL Server Development (2000)
 AVG a COUNT result using a GROUP?

Author  Topic 

Woodzy
Starting Member

7 Posts

Posted - 2005-01-16 : 16:36:29
Hello
How do you AVG a COUNT result? I'm fairly new to SQL and can't find this in my book (SQL Server 2000). Any pointers would be appreciated.

SELECT Genre, COUNT (Genre) as 'Movies Per Genre'
FROM Movies IN
WHERE Movies IN(SELECT AVG ([Movies Per Genre]))
GROUP BY Genre


Thanks, Woodzy

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-01-16 : 18:14:52
[code]select
Genre,
count(*) as [Movies Per Genre],
( select avg(cnt)
from( select cast(count(*) as float) as cnt
from Movies
group by Genre) as moviecnt ) as [Avg Movies Per Genre]
from
Movies
group by
Genre[/code]

rockmoose
Go to Top of Page

Woodzy
Starting Member

7 Posts

Posted - 2005-01-16 : 21:10:27
quote:
Originally posted by rockmoose

select
Genre,
count(*) as [Movies Per Genre],
( select avg(cnt)
from( select cast(count(*) as float) as cnt
from Movies
group by Genre) as moviecnt ) as [Avg Movies Per Genre]
from
Movies
group by
Genre


rockmoose



Thanks Rockmoose, I was not even sure where to start with this!
Go to Top of Page
   

- Advertisement -