| Author |
Topic |
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-25 : 12:29:03
|
select s.survey_id from survey s join survey_response sr on s.survey_id = sr.survey_idjoin survey_answer sa on sa.answer_id = sr.answer_idgroup by s.survey_idhaving sum(sa.weight)= sum(sa.high)Result-----------survey_id443446450451453458459461but i want the count of the s.survey_id i.e 8 so i do this:select count(s.survey_id )from survey s join survey_response sr on s.survey_id = sr.survey_idjoin survey_answer sa on sa.answer_id = sr.answer_idgroup by s.survey_idhaving sum(sa.weight)= sum(sa.high)result------76888868 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-11-25 : 12:44:57
|
| Do you have a question or a problem? |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-25 : 12:48:57
|
| See in the result i want 8 only which is the count of tthe survey_id..... do u get it now??am i being clear enough? |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-11-25 : 12:54:08
|
remove the "group by" and try like this...select count(distinct s.survey_id )from survey s join survey_response sr on s.survey_id = sr.survey_idjoin survey_answer sa on sa.answer_id = sr.answer_idwhere sum(sa.weight)= sum(sa.high) |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 01:48:03
|
| sum is aggregate function man... u cant use this in where |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-26 : 02:04:31
|
| Try thisselect count(survey_id ) from(select s.survey_idfrom survey s join survey_response sr on s.survey_id = sr.survey_idjoin survey_answer sa on sa.answer_id = sr.answer_idgroup by s.survey_idhaving sum(sa.weight)= sum(sa.high)) as tMadhivananFailing to plan is Planning to fail |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 02:24:38
|
| Yes that worked ... thnx Madhivanan !! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-26 : 02:28:55
|
quote: Originally posted by nitsmooth Yes that worked ... thnx Madhivanan !!
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 04:45:43
|
| Hi Madhivanan,Could u help me hereI have written these two queriesselect Assignee, count(callid) Delighted from( select s.callid, ag.assignee from survey s join survey_response sr on s.survey_id = sr.survey_id join survey_answer sa on sa.answer_id = sr.answer_id join asgnmnt ag on s.callid = ag.callid group by s.callid, ag.assignee having sum(sa.weight)= sum(sa.high))Dgroup by assigneeREsult------Assignee DelightedNitish Dhar 2Suzette Strayer 7select Assignee, count(survey_id)TotalSurvey from( select s.survey_id, ag.assignee from survey s join survey_response sr on s.survey_id = sr.survey_id join survey_answer sa on sa.answer_id = sr.answer_id join asgnmnt ag on s.callid = ag.callid group by s.survey_id, ag.assignee)Tgroup by assigneeResult-------Assignee TotalSurveyNitish Dhar 6Suzette Strayer 18No i want to combine the two results and find the percentageSomething like this:Assignee TotalSurvey Delighted PercentageDelightedNitish Dhar 2 6 33%Suzette Strayer 7 18 38%How do i do this ??? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-26 : 05:46:35
|
| select Assignee, count(case when weight=high then callid end) as Delighted,count(survey_id) as TotalSurvey ,count(case when weight=high then callid end)*100.0/count(survey_id) as PercentageDelightedfrom(select s.callid, ag.assignee,sum(sa.weight) as weight,sum(sa.high) as highfrom survey s join survey_response sr on s.survey_id = sr.survey_idjoin survey_answer sa on sa.answer_id = sr.answer_idjoin asgnmnt ag on s.callid = ag.callidgroup by s.callid, ag.assignee) Tgroup by assigneeMadhivananFailing to plan is Planning to fail |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 05:59:12
|
Worked like charm !!! Thanks Madi |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-26 : 06:01:26
|
quote: Originally posted by nitsmooth Worked like charm !!! Thanks Madi 
You are welcome Try to understand the code MadhivananFailing to plan is Planning to fail |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 06:04:51
|
| Ya dude ... i m gon thru it now !! |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 06:14:12
|
| Hey Madi what do you refer mostly for sql... any book or online tutorial u suggest ?? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-11-26 : 06:19:27
|
quote: Originally posted by nitsmooth Hey Madi what do you refer mostly for sql... any book or online tutorial u suggest ??
Online tutorialsAlso regularly follow SQL Team MadhivananFailing to plan is Planning to fail |
 |
|
|
nitsmooth
Yak Posting Veteran
68 Posts |
Posted - 2009-11-26 : 06:36:39
|
jst what i wanted to hear !!! thnx |
 |
|
|
|