Avatar of jsawicki
jsawicki
 asked on

Retrieving a Percentage of Users in Query

I have a report that i imported into access and need a query that displays the top 25% of users based on their usage which is times run.  I then these users average duration based on their (total duration/times run) and then divided by 60 so i can get the total hours.  

Providing me the SQL would be helpful since i am learning this coding and obtaining concrete examples help.  

Attached is spreadsheet that provides the data and output i require.
Dragon1.xls
Microsoft Access

Avatar of undefined
Last Comment
Mez4343

8/22/2022 - Mon
Norie

I don't quite understand the result.

User35 has run 78 times not 350, and User4 has run 224 times not 369.
ASKER CERTIFIED SOLUTION
Mez4343

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jsawicki

ASKER
i was just putting in dummy numbers in the bottom, sorry for the confusion.  Mez, i will try your code tomorrow at work and let you know.  Thanks
jsawicki

ASKER
It worked perfectly, thanks mez
Your help has saved me hundreds of hours of internet surfing.
fblack61
jsawicki

ASKER
Mez,

what code do i need to add to remove all users whose usage field is null before calculating the top 25%
Mez4343

ok, great.

<<what code do i need to add to remove all users whose usage field is null before calculating the top 25%>>

I would add a  WHERE clause to filter out users that you do not want to be part of the SUM() function rather than trying to filter NULL from the final result. Like this but modify the WHERE clause as needed.

SELECT TOP 25 PERCENT [Last User], SUM([Total Duration] / [Times Run] / 60)  as 'Average Duration'
FROM Table1
WHERE [TotalDuration] > 0 AND [Times Run] > 0
GROUP BY [Last User]