Re: Return select statement with sql case statement - Mailing list pgsql-general

From Ron
Subject Re: Return select statement with sql case statement
Date
Msg-id 54d91883-6b0d-a8be-5aa4-d70bd5867c7c@gmail.com
Whole thread Raw
In response to Re: Return select statement with sql case statement  (hmidi slim <hmidi.slim2@gmail.com>)
Responses Re: Return select statement with sql case statement  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On 07/04/2018 10:32 AM, hmidi slim wrote:
> Actually, I need the use of case because based on the numberOfPremiumDays 
> there are different type of treatment:
> select numberOfPremiumDays
>             case  when numberOfPremiumDays = date_part('day', 
> ('2018-11-05'::timestamp) - ('2018-11-01'::timestamp)) then
>                 select product_id,
>                 premium_price,
>                 period_price
>                 from product
>                 where occupation_type_id = 1
>                 group by product_id, occupation_type_id
>            else
>                 select product_id,
>                 classic_price,
>                 period_price
>                 from product1
>                 where occupation_type_id = 1
>                 group by product_id, occupation_type_id
>

Then try:
select product_id,
case when numberOfPremiumDays = date_part('day', ('2018-11-05'::timestamp) - 
('2018-11-01'::timestamp)) then
            premium_price
        else
            period_price
        end as the_price
from product
where occupation_type_id = 1
order by product_id, occupation_type_id


-- 
Angular momentum makes the world go 'round.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Unable to Connect to DB Instance
Next
From: Adrian Klaver
Date:
Subject: Re: Return select statement with sql case statement