473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getting max count - error: error aggregate function calls may not be nested

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

Expand|Select|Wrap|Line Numbers
  1. select max(count(*))
  2. from buys
  3. group by v_id
bt i have the error aggregate function calls may not be nested
plzzz help
Apr 19 '08 #1
6 7176
siva538
44
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.  
Apr 19 '08 #2
poopsy
50
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
Apr 19 '08 #3
deric
92
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.
Apr 21 '08 #4
Expand|Select|Wrap|Line Numbers
  1. select max(cnt) from 
  2. (
  3. select count(*) as cnt
  4. from dbo.TrendCLUBS
  5. group by Club_HomeColor
  6. ) a
Now try the above one....
Apr 21 '08 #5
siva538
44
it doesnt work..it gives me syntax error near 1
plzz help

If your database is sql server then it should work !
Apr 21 '08 #6
tested.

Expand|Select|Wrap|Line Numbers
  1. select max(cnt) from
  2. (
  3. select count(*) as cnt
  4. from dbo.TrendCLUBS
  5. group by Club_HomeColor
  6. ) a
is good and works fine with SQL Server.
Jan 31 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
6
by: Geetha | last post by:
I searched in the Oracle documents what count (1) meant and I could not find an answer. Can some one explain what Oracle does internally when use count (1) VS count (*). Thank you very much in...
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
1
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
7
by: Chris | last post by:
I am trying to increase/decrease the value of $_SESSION by 1 after clicking on a link e.g index.php?gotoWk=nxtWk and index.php? gotoWk=lstWk. I'm sure you will get the drift if you look at the code...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.