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.
| Author |
Topic |
|
boogi88
Starting Member
5 Posts |
Posted - 2010-03-01 : 08:20:33
|
| select count(*) as nor, sum(rating) as totalPoints, rating = CASE ((sum(rating))/(count(*))) when round(((sum(rating))/(count(*))), 2) = 5 then 1 when round(((sum(rating))/(count(*))), 2) = 4 then 2 when round(((sum(rating))/(count(*))), 2) = 3 then 3 when round(((sum(rating))/(count(*))), 2) = 2 then 4 when round(((sum(rating))/(count(*))), 2) <= 1 then 5 ELSE 10 END as points, sum(rating)/count(*) as cond2 from tblratings where ratingType='Blog' and ratingParentID='113'resultnor totalPoints points cond2 18 90 0 5if u see this query cond2 gives result 5 but the condition did not return the proper value....Help me find out y?? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-01 : 08:26:32
|
You have condition in CASE and also in WHEN that isn't ok. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
boogi88
Starting Member
5 Posts |
Posted - 2010-03-01 : 08:28:17
|
| didn't get u..... could u be more specific?? |
 |
|
|
boogi88
Starting Member
5 Posts |
Posted - 2010-03-01 : 08:30:34
|
| Actually thr is no condition in case.....Please take a closer look at the query....If i m wrong please post the correct query..... |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-03-01 : 08:33:14
|
quote: Originally posted by boogi88 didn't get u..... could u be more specific??
Try thisselect count(*) as nor, sum(rating) as totalPoints, CASE ((sum(rating))/(count(*)))when 5 then 1when 4 then 2when 3 then 3when 2 then 4when <= 1 then 5ELSE 10END as points, sum(rating)/count(*) as cond2from tblratings where ratingType='Blog' and ratingParentID='113'PBUH |
 |
|
|
boogi88
Starting Member
5 Posts |
Posted - 2010-03-01 : 08:37:42
|
| This is wat i got......You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<= 1 then 5ELSE 10END as points, sum(rating)/count(*) as cond2from tblrati' at line 6 |
 |
|
|
boogi88
Starting Member
5 Posts |
Posted - 2010-03-01 : 08:48:15
|
| Thanks.... it worked Gr8....Here is my finished query.......select count(ratingID) as nor, sum(rating) as totalPoints, round((sum(rating))/(CASE round(((sum(rating))/(count(ratingID))))when 5 then 1when 4 then 2when 3 then 3when 2 then 4when 1 then 5END)) as points, sum(rating)/count(ratingID) as cond2from tblratings where ratingType='Blog' and ratingParentID='113' |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-03-01 : 08:53:17
|
| No but u have missed the <= part.You can modify ur query this wayselect count(*) as nor, sum(reading) as totalPoints, CASE when AVG(Reading)=5 then 1...CASE when <= 1 then 5ELSE 10END as points, sum(rating)/count(*) as cond2from tblratings where ratingType='Blog' and ratingParentID='113'And I beleive u need average so u can directly use avg function instead of doing (sum(rating))/(count(*))the way I did.PBUH |
 |
|
|
|
|
|
|
|