|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
My brain hurts - Different totals in same query
I need to display from a table, the count of all the courses one person has taken, the count of the ones they passed, and the percentage complete and I can't wrap my brain around this.
Has to be done in a single SQL statement, no breaks, computes, etc. And I can't write a function for it. Help! TIA |
|
#2
|
|||
|
|||
|
Hi,
Try using analytic functions - this should do the trick. G. |
|
#3
|
||||
|
||||
|
something like this perhaps?
Code:
select person
, count(*) as coursestaken
, sum( case when passed='Y'
then 1 else 0 end ) as coursespassed
, sum( case when passed='Y'
then 1 else 0 end )
* 100 / count(*) as percentcomplete
from yourtable t1
group
by person
|
|
#4
|
|||
|
|||
|
Ohhh...slick... I like that, thanks r937!
![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > My brain hurts - Different totals in same query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|