Last active
August 31, 2018 06:18
-
-
Save abelcallejo/190beb00a555b9f430ead1e11d2574ff to your computer and use it in GitHub Desktop.
Using CASE-WHEN statement in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Minimal example **/ | |
SELECT | |
CASE | |
WHEN 1 > 0 THEN 'one is greater than zero' | |
ELSE 'something else' | |
END AS "ALIASED_FIELD_NAME_HERE" | |
/** In table example **/ | |
SELECT | |
CASE | |
WHEN table_name.field_name::integer > 0 THEN 'it is more than zero' | |
WHEN table_name.field_name::integer = 1 THEN 'it is single' | |
ELSE 'something else' | |
END AS "ALIASED_FIELD_NAME_HERE" | |
FROM | |
table_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment