Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. peak hours query

peak hours query

Scheduled Pinned Locked Moved Database
databasemysqlcomhelpannouncement
4 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I need a help please I am using MySQL. I have a patients database. In patients database I have a table called visit with created_date field as timestamp datatype. I want to do a query which will give the break down of total number of patients in every hour like this: hour -------- Patients 00 -------- 7 01 -------- 8 02 -------- 11 03 -------- 4 ... ... ... 20 -------- 5 21 -------- 10 22 -------- 3 23 -------- 0

    Technology News @ www.JassimRahma.com

    M B S 3 Replies Last reply
    0
    • J Jassim Rahma

      Hi, I need a help please I am using MySQL. I have a patients database. In patients database I have a table called visit with created_date field as timestamp datatype. I want to do a query which will give the break down of total number of patients in every hour like this: hour -------- Patients 00 -------- 7 01 -------- 8 02 -------- 11 03 -------- 4 ... ... ... 20 -------- 5 21 -------- 10 22 -------- 3 23 -------- 0

      Technology News @ www.JassimRahma.com

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Create a query that extracts the hours (use datepart(h,datefield) component of the created date as an integer. A simple group by will then give you the result you need.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • J Jassim Rahma

        Hi, I need a help please I am using MySQL. I have a patients database. In patients database I have a table called visit with created_date field as timestamp datatype. I want to do a query which will give the break down of total number of patients in every hour like this: hour -------- Patients 00 -------- 7 01 -------- 8 02 -------- 11 03 -------- 4 ... ... ... 20 -------- 5 21 -------- 10 22 -------- 3 23 -------- 0

        Technology News @ www.JassimRahma.com

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        The amount of 0 items will make a problem with Mycroft Holmes' answer - that line won't show up. You need the numbers from 0-23 (somehow generated, or make a table "Hours" with those values, and then JOIN the query suggested by Mycroft Holmes to it, and replace NULL values with 0.

        1 Reply Last reply
        0
        • J Jassim Rahma

          Hi, I need a help please I am using MySQL. I have a patients database. In patients database I have a table called visit with created_date field as timestamp datatype. I want to do a query which will give the break down of total number of patients in every hour like this: hour -------- Patients 00 -------- 7 01 -------- 8 02 -------- 11 03 -------- 4 ... ... ... 20 -------- 5 21 -------- 10 22 -------- 3 23 -------- 0

          Technology News @ www.JassimRahma.com

          S Offline
          S Offline
          S Douglas
          wrote on last edited by
          #4

          Not sure if this will directly work in MySQL, but here is what I would do in SQL Server

          SELECT
          DATEPART(hh, Created_Date) [Hours]
          , COUNT(*) [Patients]
          FROM Visit
          GROUP BY
          DATEPART(hh, Created_Date)

          EDIT There is a format function in MySQL that will return the hour https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format[^]


          Common sense is admitting there is cause and effect and that you can exert some control over what you understand.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups