Answer the question
In order to leave comments, you need to log in
How to conditionally extract different data in postgres?
Good afternoon,
There is a table:
tarifs
--------------
id
price
percent (default NULL)
I want to pull out if percent is not NULL :
( (tarifs.price * tarifs.percent ) / 100 )
Otherwise, you just need to pull out price .
How can this be done conditionally in postgres ?
Answer the question
In order to leave comments, you need to log in
As in any other DBMS
SELECT
CASE
WHEN percent IS NOT NULL THEN price * percent / 100
ELSE price
END as price
FROM tarifs
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question