473,396 Members | 1,907 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,396 software developers and data experts.

max count

50
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
Apr 19 '08 #1
4 16743
rski
700 Expert 512MB
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
maybe like that

Expand|Select|Wrap|Line Numbers
  1. select max(column) from (select count(*) as column from buys group by v_id) t;
  2.  
Apr 19 '08 #2
poopsy
50
maybe like that

Expand|Select|Wrap|Line Numbers
  1. select max(column) from (select count(*) as column from buys group by v_id) t;
  2.  

thx a lot it works...but can u help me some more plzz...i need to get the corresponding v_id where the count is maximum..
i tried doing this
Expand|Select|Wrap|Line Numbers
  1. select t.vid,max(c) from (select vid,count(*) as c from buys group by vid) t;
bt i get the error
ERROR: column "t.vid" must appear in the GROUP BY clause or be used in an aggregate function
i tried using top 1 bt i dnt knw how to use it..
i did this
Expand|Select|Wrap|Line Numbers
  1. select TOP 1 t.vid,max(c) from (select vid,count(*) as c from buys group by vid) t group by t.vid;
bt i get a syntax error near 1..

plzz help
Apr 20 '08 #3
rski
700 Expert 512MB
thx a lot it works...but can u help me some more plzz...i need to get the corresponding v_id where the count is maximum..
i tried doing this
Expand|Select|Wrap|Line Numbers
  1. select t.vid,max(c) from (select vid,count(*) as c from buys group by vid) t;
bt i get the error
ERROR: column "t.vid" must appear in the GROUP BY clause or be used in an aggregate function
i tried using top 1 bt i dnt knw how to use it..
i did this
Expand|Select|Wrap|Line Numbers
  1. select TOP 1 t.vid,max(c) from (select vid,count(*) as c from buys group by vid) t group by t.vid;
bt i get a syntax error near 1..

plzz help
I don't think there is TOP option in postgres, I guess you mean LIMIT clause.
Here is the solution, probably not the best one but I'm to tired to look for better one
Expand|Select|Wrap|Line Numbers
  1. select vid from (select vid ,count(*) as k from buys group by vid)as t where k=(select max(k) from (select count(*) as k from buys group by vid) l);
  2.  
Apr 20 '08 #4
select t.vid,max(c) from (select vid,count(*) as c from buys group by vid) t group by vid limit 1;
Feb 13 '14 #5

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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.