|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
SQL Query
Hi there,
I have a table such as thi ProgramName Program Code ASDF SC SEDE EK SEDE JS KEREDE SC DKJELK EK skee EK SEDE EK Now what I would like to do is obtain a report such as this ProgramName SC EK JS (NameOfProgram) (Count) (Count) (Count) so how would this work as a query?? would I have to make 3 different queries, for the count of SC, EK and JS, cause thats the way I have it set up, and was wondering if there was a better way of doing it. |
|
#2
|
||||
|
||||
|
if it's just those three values, then yeah, you can do it fairly easily (if it's a variuable number of values, then it's a true crosstab, and very hard to do)
instead of a count, what you want is a sum, actually three sums, and each of the three sums is a sum of the number of 1s for that value it's actually easier to understand in sql than in english -- Code:
select ProgramName
, sum(
case when ProgramCode='SC' then 1 else 0 end
) as SC
, sum(
case when ProgramCode='EK' then 1 else 0 end
) as EK
, sum(
case when ProgramCode='JS' then 1 else 0 end
) as JS
from yourtable
group
by ProgramName
rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > SQL Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|