Query - top members based on total and month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flydev
    New Member
    • Feb 2008
    • 33

    Query - top members based on total and month

    Hello,

    I am trying to build a query that will display the top 5 members of my "virtual airline" based on the total hours flown for the month. Whenever a pilot files a completed flight plan, the data is stored in a table containing the following rows.

    MID (member ID)
    hours (hours flown)
    month (the month of the flight)

    There will be hundreds of flights per member (or MID).

    I need a query that will sum the hours for each pilot for this month, then order it from highest to lowest (limit of 5). I've tried for hours to come up with the proper query and I keep drawing a blank.

    The site is written in PHP. Thank you for any help you can provide! I am sorry if I left out anything, I am new to this site and MySQL
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    This should do it[code=sql] SELECT MID,month,sum(h ours) as Total_hours from table_name GROUP BY MID, month;[/code]Ronald

    Comment

    • flydev
      New Member
      • Feb 2008
      • 33

      #3
      Oh man you're a life saver! Thanks so much!

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You are welcome. See you again next time.

        Ronald

        Comment

        Working...