Solved

Retrieving a Percentage of Users in Query

Posted on 2012-03-15
6
227 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

737 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