Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 10th, 2012, 03:06 PM
MikeW33 MikeW33 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 1 MikeW33 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 19 sec
Reputation Power: 0
SQL Query to calculate staff pass rates from a testing results table

Hi,

Im looking for some help building a query on the below table which stores the results of testing carried out on work cases:

case_id staff_name result case_date
1 dave pass 01-May-12
2 dave fail 01-May-12
4 jim pass 01-May-12
5 dave pass 02-May-12
6 dave pass 02-May-12



I want the query to return for each member of staff who has had a case tested in a day a pass rate for that member of staff that day. The result would look something like:

case_date staff_name tests passes score
01-May-12 dave 2 1 50%
01-May-12 jim 1 1 100%
02-May-12 dave 2 2 100%



I have managed to make separate queries for getting the number of tests per staff per day

SELECT staff_name, Count(result), case_date
FROM results
GROUP BY staff_name, case_date;

SELECT case_date, staff_name, Count(result)
FROM results
WHERE result="pass"
GROUP BY staff_name, case_date

But i dont know how to combine the 2 and then work out a percentage in SQL.

Can anyone help?

Thanks

Mike

Reply With Quote
  #2  
Old May 10th, 2012, 04:08 PM
shammat shammat is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Oct 2003
Location: Germany
Posts: 2,685 shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level)shammat User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 3 Days 19 h 56 m 12 sec
Reputation Power: 284
Code:
select staff_name,
       case_date,
       total_cases / passed_cases as percentage
from (
    SELECT staff_name, 
           case_date, 
           Count(result) as total_cases,
           count(case when result = 'pass' then 1 else null end) as passed_cases
    FROM results
    GROUP BY staff_name, case_date;
) t

In the future please make your code readable by formatting it using [code] tags.

See here for details: http://forums.devshed.com/misc.php?do=bbcode

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL Query to calculate staff pass rates from a testing results table

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap