473,804 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query - top members based on total and month

33 New Member
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
Feb 29 '08 #1
3 1448
ronverdonk
4,258 Recognized Expert Specialist
This should do it
Expand|Select|Wrap|Line Numbers
  1.  SELECT MID,month,sum(hours) as Total_hours from table_name GROUP BY MID, month;
Ronald
Feb 29 '08 #2
flydev
33 New Member
Oh man you're a life saver! Thanks so much!
Feb 29 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
You are welcome. See you again next time.

Ronald
Feb 29 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1251
by: Jimmy Tran | last post by:
Hi All, I have a table below and I want to design a query to pull all the members from the TABLE into a Query Result and into a single column with points assigned appropriately, but I am having a lot of difficulties doing this. Any help is greatly appreciated. TABLE MEMBER1 MEMBER2 POINTS Joe Don 2 Macy 1
3
2822
by: Tom | last post by:
I have a report based on a crosstab query that shows monthly automobile sales. The report is grouped on Make so that it shows the models under each Make. I want to now get the subtotals by Make and then the total for all for each month. I find that the control source for the textboxes in the detail section have a date value such as Jan_03 rather than dollars but when I run the report dollars appears in the report. Obviously I can't sum up...
4
2026
by: ED | last post by:
I am attempting to to write a query that has a numerous nested IIf statements. The problem that I am having is that it is to long of a query to be built in design mode and when I build it in sql mode after a certain point it give me the error message that the expression is to complex. Below is the sql code that I am using (this works so far, anything added to the code will give me the to complex error message.) SELECT .WONUM, .,...
2
2601
by: jacob | last post by:
I am using a membership database and trying to exclude certain records that have not paid dues for that particluar fund. I have a query that will pull up all members that have renewed for the month and the funds that they have paid. When I run a report, I only want to include those that have paid for a particular fund. What do I put in the query to exclude those that have not paid? I thought putting something like "include if it is >1" or...
3
2100
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is for membership information. This particular table, called tblMembershipInfo, has fields/columns as follows - fldMemNum - Member Number fldActionDate - The date when the entry was made in that row - Data type is Date/Time, no format specified
2
4000
by: dath | last post by:
Hi, Searched the forum and found a lot on passing form input to aquery but not the other way around. Here is the situation: I have a timesheet form based on a subform query that asks the user for the Month and their last name. The fields in the table being updated include: FY, Month, Employee ID, Task Number, hours. The query then displays the results in data sheet view on the form. I have been asked by users to display total they...
2
3429
by: captainmorgan | last post by:
I have a simple query, which consists of a few project dates, which in return need to be charged based on completion. That said, I wanted to create a CHARGE field which would calculate the total charge based on the projects completed (Estimates & Layouts). Just to make this complicated, there are 2 branches that get discounted charges. Below, I have included the if statements that I desire to take affect, I'm not sure how to implement them...
15
2025
by: Widge | last post by:
Hi, I wondered if you could help me with an issue I'm having. Currently I have a rebate calculation that is running off two tables: 1) A list of suppliers and the rebate %ages relevant to them 2) A ongoing list of invoice details, including a month/year period and an invoice total At the moment, I can happily run the rebate calculation for the current month. What I would like to do is begin to track changes in supplier rebate rates...
25
2547
by: Darsin | last post by:
Hi all I need to perform a summation on a column of a table based on a criteria given in another column in the same table. The catch is i need to perform different sums according to the number of criterias in the criteria column, in a single query. the structure of the table is somethinmg like this (only relevant columns are shown) TABLE1 Value - numeric(20,6) Month - int
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10359
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.