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
jsawickiAsked:
Who is Participating?
 
Mez4343Connect With a Mentor Commented:
Something like this?

SELECT TOP 25 PERCENT [Last User], SUM([Total Duration] / [Times Run] / 60)  as 'Average Duration'
FROM Table1
GROUP BY [Last User]
0
 
NorieVBA ExpertCommented:
I don't quite understand the result.

User35 has run 78 times not 350, and User4 has run 224 times not 369.
0
 
jsawickiAuthor Commented:
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
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
jsawickiAuthor Commented:
It worked perfectly, thanks mez
0
 
jsawickiAuthor Commented:
Mez,

what code do i need to add to remove all users whose usage field is null before calculating the top 25%
0
 
Mez4343Commented:
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]
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.