?
Solved

Retrieving a Percentage of Users in Query

Posted on 2012-03-15
6
Medium Priority
?
230 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 2000 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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…
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…
Suggested Courses

771 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