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 > Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-10, 16:42
hendaz hendaz is offline
Registered User
 
Join Date: Apr 2010
Posts: 1
Query Help

Hi, I have a db which tracks orders. I would like a query which lists the date and time of the most orders in a given calendar month.

e.g
date time number
13/4/10 09:00 - 10:00 150
11/4/10 10:00 - 11:00 148
....


Any Ideas ???
Reply With Quote
  #2 (permalink)  
Old 04-15-10, 17:04
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Here you simply use the DATE_FORMAT function on the date field. As follows:

SELECT DATE_FORMAT(fieldname, '%d/%m/%y %H') as timeofday, COUNT(1) AS RESULT
FROM tablename
GROUP BY DATE_FORMAT(fieldname, '%d/%m/%y %H')
ORDER BY COUNT(1) DESC;

The timeofday will return entries as follows:

13/04/10 09 - number of occurences
13/04/10 10 - number of occurrences

The 09 and 10 represent the hour of the day in which these occurred and the order by to provide them in the most to the least.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com

Last edited by it-iss.com; 04-15-10 at 17:11. Reason: Incomplete SQL
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