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)
 Result set

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_test
where question_1 in ('1','2','3','4')
group by country,month

select 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/
Go to Top of Page

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 this
SELECT		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 Satisfied
FROM tbl_raw_CSAT_test
GROUP BY Country,
[Month]
ORDER BY Country,
[Month]


E 12°55'05"
N 56°04'39"
Go to Top of Page

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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-24 : 12:16:12




E 12°55'05"
N 56°04'39"
Go to Top of Page

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
Go to Top of Page

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"
Go to Top of Page

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/
Go to Top of Page

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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-24 : 13:10:04
And, for one of many places, here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=74740



E 12°55'05.76"
N 56°04'39.42"
Go to Top of Page
   

- Advertisement -