E
E
EVOSandru62015-12-04 06:07:42
PostgreSQL
EVOSandru6, 2015-12-04 06:07:42

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

1 answer(s)
A
Andrey Mokhov, 2015-12-04
@EVOSandru6

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 question

Ask a Question

731 491 924 answers to any question