tags:

views:

42

answers:

5

Query:

  SELECT * 
    FROM Post 
ORDER BY Post.rating <-- Here , i want ( Post.rating * 5 ) when Post.recommended = 1 ) 

Thanks all people.

+4  A: 

Use:

  SELECT p.*
    FROM POST p
ORDER BY CASE 
           WHEN p.recommended = 1 THEN p.rating * 5
           ELSE p.rating
         END
OMG Ponies
+1 Clear, Readable and easy to understand.
Ruel
+1  A: 
SELECT * FROM Post 
ORDER BY case Post.rating when 1 then post.rating * 5 else post.rating end
Michael Pakhantsov
Three essentially identical answers within 1 minute. With luck, at least one of us is right!
Jonathan Leffler
@Jonathan Leffler: All are right ;-)
zerkms
+1  A: 

Does this work?

SELECT *
  FROM Post
 ORDER BY CASE Recommended WHEN 1 THEN Rating * 5 ELSE Rating END

Since there's only one table, the column references are unambiguous, so I removed the Post. prefixes, which avoids the horizontal scroll-bar.

Jonathan Leffler
+1  A: 
  SELECT * 
    FROM Post 
ORDER BY Post.rating * IF(recommended = 1, 5, 1)
zerkms
A: 

try

SELECT * 
    FROM Post 
ORDER BY if(Post.recommended = 1,Post.rating * 5,Post.rating)
Yogesh