Results 1 to 2 of 2

Thread: Query Help

  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Unanswered: 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 ???

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    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.
    Last edited by it-iss.com; 04-15-10 at 18:11. Reason: Incomplete SQL
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •