Author |
Topic |
rookie_sql
Constraint Violating Yak Guru
443 Posts |
Posted - 2007-07-24 : 11:52:49
|
I need to query a column and return the resuls but i also then neeed to query the same column and also return an another result set,Here is what i have so far.. i tried to do a sub query but it was returning all the same values for the Satisfied column,select count (question_1)as Number_Surveyed, count(question_2) as Question_2, country, [month]from tbl_raw_CSAT_testwhere question_1 in ('1','2','3','4')group by country,monthselect count (question_1) as Satisfied, country, [month]from tbl_raw_CSAT_test where question_1 in ('1','2')group by country,[month] |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-07-24 : 11:57:15
|
Provide some sample data and expected output.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-24 : 12:13:39
|
In the first query, if you count QUESTION2, shouldn't the WHERE filter work on Question2 column?Play around with thisSELECT Country, [Month], SUM(CASE WHEN question_1 in ('1', '2', '3', '4') THEN 1 ELSE 0 END) AS Number_Surveyed, SUM(CASE WHEN question_1 in ('1', '2') THEN 1 ELSE 0 END) AS SatisfiedFROM tbl_raw_CSAT_testGROUP BY Country, [Month]ORDER BY Country, [Month] E 12°55'05"N 56°04'39" |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-07-24 : 12:14:56
|
SELECT 'Numbered_Surveyed' = SUM(CASE WHEN question_1 in ('1','2','3','4') THEN 1 ELSE 0 END) ,'Satisfied' = SUM(CASE WHEN question_1 in ('1','2') THEN 1 ELSE 0 END) ,'Question_2' = count(question_2)-- This is just a guess, it isn't clear exactly what you want counted ,country ,[month]FROM tbl_raw_CSAT_test GROUP BY country,[month]Jim |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-24 : 12:16:12
|
 E 12°55'05"N 56°04'39" |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-07-24 : 12:30:06
|
If that's aimed at me I am still taking a great deal of satisfaction in knowing that even though your answer posted first, that mine is essentially the same answer and I didn't cheat off of yours! Jim |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-24 : 12:36:22
|
No offense. We do this thing when there is minimal time between same answers. No other reason. E 12°55'05.76"N 56°04'39.42" |
 |
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-07-24 : 12:38:54
|
quote: Originally posted by Peso No offense. We do this thing when there is minimal time between same answers. No other reason. E 12°55'05.76"N 56°04'39.42"
Yeah we do it all the time..see me Peso .. Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2007-07-24 : 12:54:34
|
Then I made it 20 posts without getting on the twit list! Yahoo!Jim |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|