Connecting Tech Pros Worldwide Help | Site Map

max count

Member
 
Join Date: Nov 2006
Posts: 50
#1: Apr 19 '08
hi all
i have the following query, i need to get the max count from a table

select max(count(*))
from buys
group by v_id

bt i have the error aggregate function calls may not be nested
plzzz help
Member
 
Join Date: Jun 2007
Posts: 44
#2: Apr 19 '08

re: max count


Quote:

Originally Posted by poopsy

hi all
i have the following query, i need to get the max count from a table

select max(count(*))
from buys
group by v_id

bt i have the error aggregate function calls may not be nested
plzzz help

Probably you are looking for this !
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 * FROM 
  2. (
  3.     SELECT v_id, COUNT(*) AS COUNT
  4.     FROM buys
  5.     GROUP BY v_id
  6. ) A
  7. ORDER BY 2 DESC
  8.  
Member
 
Join Date: Nov 2006
Posts: 50
#3: Apr 19 '08

re: max count


Quote:

Originally Posted by siva538

Probably you are looking for this !

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 * FROM 
  2. (
  3.     SELECT v_id, COUNT(*) AS COUNT
  4.     FROM buys
  5.     GROUP BY v_id
  6. ) A
  7. ORDER BY 2 DESC
  8.  


it doesnt work..it gives me syntax error near 1
plzz help
Member
 
Join Date: Dec 2007
Posts: 81
#4: Apr 21 '08

re: max count


Quote:

Originally Posted by poopsy

hi all
i have the following query, i need to get the max count from a table

select max(count(*))
from buys
group by v_id

bt i have the error aggregate function calls may not be nested
plzzz help

You created another thread with the same content as this thread.. You need to review the posting guidelines of this site again. :D

Let's get back to your original script. You cannot use the aggregate function Count() as a parameter to some other aggregate functions like Max(). Anyhow, because your statement doesn't have Where clause and the count function does not specify a particular column/value to count, it will just output rows with always the same value. So, what particular count in your table are you trying to get?
If you can provide sample rows and your expected output, that would be easy for me to help you.
ganeshkumar08's Avatar
Newbie
 
Join Date: Jan 2008
Posts: 31
#5: Apr 21 '08

re: max count


select max(cnt) from
(
select count(*) as cnt
from dbo.TrendCLUBS
group by Club_HomeColor
) a

Now try the above one....
Member
 
Join Date: Jun 2007
Posts: 44
#6: Apr 21 '08

re: max count


Quote:

Originally Posted by poopsy

it doesnt work..it gives me syntax error near 1
plzz help


If your database is sql server then it should work !
Reply