lundi 8 janvier 2018

How to return a value per WHERE conditions in postgresql SELECT in single query?

I'm looking to write a postgresql SELECT in single query with WHERE conditions :

SELECT 1 FROM foo_table
WHERE a = true
    AND b = true
    AND c = true

to do the following :

if (a and b and c) :
    return 1
elif not ( a and b) :
    return 2
elif not ( a and b and c) :
    return 3

What is the best way?

Aucun commentaire:

Enregistrer un commentaire