Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
supergirl_gem
Starting Member
4 Posts |
Posted - 2008-09-01 : 04:35:44
|
Hi,I've already got a query which looks as follows:Select Location, Count(Case When total >= 5 then total end) green, Count(Case When total < 5 and total > - 10 then total end) amber, Count(Case When total <= -10 then total end) redFromtotalValuesGroup by Locationthis currently outputs my table as below:Location Red Amber Green1 2 I want to change this so it's output as follows: Location 1 Location 2Red Amber Green If anyone has any suggestions I would appreciate it.ThanksGemma |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-09-01 : 04:47:58
|
[code]SELECT Status, COUNT(CASE WHEN Location = 'Location1' THEN Location END) AS Location1, COUNT(CASE WHEN Location = 'Location2' THEN Location END) AS Location2FROM( SELECT Location, CASE WHEN total >= 5 THEN 'Green' WHEN total < 5 AND total > -10 THEN 'Amber' WHEN total <= -10 THEN 'Red' END AS Status FROM @TABLE) dGROUP BY Status[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|