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 > MySQL > SQL Statement Help Please

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-09-04, 08:25
zitman zitman is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
SQL Statement Help Please

have a table of statistical information which can contain zero or entries for a given day. I would like a single statement to find which day has the most entries on it.

The following statement will list the days and the number of entries for that day.

SELECT Date, MAX(COUNT(ID)) FROM Stats WHERE CompanyD=2 GROUP BY Date

Is there a way I can modify this statement so it returns a single row with the Date and the number of rows for that Date, but only for the Date with the most rows.

Hope thats clear.

Z
Reply With Quote
  #2 (permalink)  
Old 04-09-04, 10:23
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select `Date`
     , count(ID) as rows
  from Stats 
 where CompanyD = 2 
group 
    by `Date`
order
    by rows desc
 limit 1
tip: don't use a reserved word like Date for a column name, you are only asking for syntax errors
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-11-04, 17:09
zitman zitman is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Many thanks.

It is actually quite simple really isn't it.

At least it is when you know how. Again thanks

Z
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