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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help this query for Count()

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2003-09-30 : 20:02:23
Hi there

I have this view this:

[EntryID; Q1_Answer; Q2_Answer; Q3_Answer]
5; Wollongong; Good; Fair;
6; Wollongong; Fair; Good;
7; Wollongong; <Null>; Fair;
8; Sydney; Good; Fair

All I want to query this view ... so the result will be like this:

[Q1_Answer; Q2_Answer_Good; Q2_Answer_Fair; Q2_Answer_Null; Q3_Answer_Good; Q3_Answer_Fair; Q3_Answer_Null]
Wollongong; 1; 1; 1; 1; 2; 0
Sydney; 1; 0; 0; 0; 1; 0

I can probbaly do it the code but I'm just wondering if I can do this on the SQL directlly

Val



JustinBigelow
SQL Gigolo

1157 Posts

Posted - 2003-09-30 : 20:31:38
something like...


select city,
sum(case when Q1_Answer='Good' then 1 else 0 end),
sum(case when Q1_Answer='Fair' then 1 else 0 end),
sum(case when Q1_Answer is null then 1 else 0 end),
etc...
from myTable
group by city


hth,
Justin

"Look at it out there orbiting like it's so cool, we will rule it with an army of replicants!"
Go to Top of Page
   

- Advertisement -