PostgreSQL SQL SELECT CASE WHEN

前端之家收集整理的这篇文章主要介绍了PostgreSQL SQL SELECT CASE WHEN前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ThesqlCASEexpression is a generic conditional expression,similar to if/else statements in other programming languages:

CASE WHEN condition THEN result
     [WHEN ...]
     [ELSE result]
END

An example:

SELECT * FROM test;

 a
---
 1
 2
 3


SELECT a,CASE WHEN a=1 THEN 'one'
            WHEN a=2 THEN 'two'
            ELSE 'other'
       END
    FROM test;

 a | case
---+-------
 1 | one
 2 | two
 3 | other


http://www.postgresql.org/docs/current/static/functions-conditional.html

猜你在找的Postgre SQL相关文章