johnlemon
johnlemon

Reputation: 21499

How to do a special order clause in postgresql?

I have a result set like this: a b c

This result will be fixed each time. What I need to do is order the rows like this a c b. How can I do that ?

Upvotes: 2

Views: 97

Answers (1)

Quassnoi
Quassnoi

Reputation: 425713

SELECT  value
FROM    mytable
ORDER BY
        CASE value WHEN 'a' THEN 1 WHEN 'c' THEN 2 WHEN 'b' THEN 3 END

Upvotes: 4

Related Questions