Solved

Retrieving a Percentage of Users in Query

Posted on 2012-03-15
6
223 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
  • 3
  • 2
6 Comments
 
LVL 33

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now