Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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; FairAll 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; 0Sydney; 1; 0; 0; 0; 1; 0I can probbaly do it the code but I'm just wondering if I can do this on the SQL directllyVal
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 myTablegroup by city
hth,Justin"Look at it out there orbiting like it's so cool, we will rule it with an army of replicants!"