tags:

views:

35

answers:

1

I questioned here this: http://stackoverflow.com/questions/3827690/how-make-this-sql-conditions-sql

but now, I want

SELECT SUM( Post.rating ) as countRating <--- THIS i want Post.rating * 5 WHEN Post.recommended = 1
FROM posts as Post
ORDER BY countRating DESC

help me

+2  A: 

Basically, use the same technique as in the answers to the other question - use a CASE expression, this time in the SUM instead of in the ORDER BY clause.

SELECT SUM(CASE Recommended WHEN 1 THEN 5 ELSE 1 END * Rating) AS countRating
  FROM posts as Post
 ORDER BY countRating DESC

If the alternative value for Recommended is 0 (a plausible guess), then you could also write:

SELECT SUM((4 * Recommended + 1) * Rating) AS countRating
  FROM posts as Post
 ORDER BY countRating DESC

And, indeed, you could do the same with the ORDER BY clause in the previous question.

Jonathan Leffler
Thanks a alot ^^, I couldn't accept your question because system dont allow, It alert "You can accept an answer in 6 minutes". I 'll accept when i return here
meotimdihia