If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problem of max(count(*))

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-02-03, 02:10
fairicky fairicky is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Problem of max(count(*))

Can someone tell me why the following sql statement cannot retrieve the
maximum count of the record:

SELECT col, max(count(*)) FROM table
GROUP BY col

And also, can I use one sql statement to retrieve the maximum count of the
record? If not, how?

Thank you more!!
Reply With Quote
  #2 (permalink)  
Old 10-02-03, 02:36
RKrick RKrick is offline
Registered User
 
Join Date: Feb 2002
Location: Germany
Posts: 141
You cannot give a function as argument for max().
Try this

SELECT col, max(colcount) from
(SELECT col, count(*) as colcount
FROM TABLE
GROUP BY col) AS aa
GROUP BY col
__________________
Rodney Krick
Reply With Quote
  #3 (permalink)  
Old 10-02-03, 03:38
fairicky fairicky is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Quote:
Originally posted by RKrick
You cannot give a function as argument for max().
Try this

SELECT col, max(colcount) from
(SELECT col, count(*) as colcount
FROM TABLE
GROUP BY col) AS aa
GROUP BY col
Could you explain in details why we cannot give a function as argument for max()
Reply With Quote
  #4 (permalink)  
Old 10-02-03, 04:39
RKrick RKrick is offline
Registered User
 
Join Date: Feb 2002
Location: Germany
Posts: 141
It makes no sense. You can give a scalar function as an argument for a column function, but not a column function as argument for a column function (look at SQL Reference).
__________________
Rodney Krick
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On