Solved

Retrieving a Percentage of Users in Query

Posted on 2012-03-15
6
228 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:jsawicki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 34

Expert Comment

by:Norie
ID: 37727137
I don't quite understand the result.

User35 has run 78 times not 350, and User4 has run 224 times not 369.
0
 
LVL 10

Accepted Solution

by:
Mez4343 earned 500 total points
ID: 37727178
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
 

Author Comment

by:jsawicki
ID: 37727297
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:jsawicki
ID: 37730513
It worked perfectly, thanks mez
0
 

Author Comment

by:jsawicki
ID: 37730639
Mez,

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

Expert Comment

by:Mez4343
ID: 37731172
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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question