From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Return select statement with sql case statement
Date: Wed, 4 Jul 2018 17:03:55 -0500
Message-ID: <54d91883-6b0d-a8be-5aa4-d70bd5867c7c@gmail.com> (raw)
In-Reply-To: <CAMsqVxsqXZ=DXZrn-gDXgpkGLrFpTpi5Ab2Ky9nKD7Kd1n_uXA@mail.gmail.com>
References: <CAMsqVxuBE0iHU=-_LCS2PyonGFvJwgrs6LLrzuGU53m7VqYBQA@mail.gmail.com>
<3524c35d-e566-9bad-e4bd-d493f05f2d4d@gmail.com>
<CAMsqVxsqXZ=DXZrn-gDXgpkGLrFpTpi5Ab2Ky9nKD7Kd1n_uXA@mail.gmail.com>
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: Return select statement with sql case statement
In-Reply-To: <54d91883-6b0d-a8be-5aa4-d70bd5867c7c@gmail.com>
References: <CAMsqVxuBE0iHU=-_LCS2PyonGFvJwgrs6LLrzuGU53m7VqYBQA@mail.gmail.com> <3524c35d-e566-9bad-e4bd-d493f05f2d4d@gmail.com> <CAMsqVxsqXZ=DXZrn-gDXgpkGLrFpTpi5Ab2Ky9nKD7Kd1n_uXA@mail.gmail.com> <54d91883-6b0d-a8be-5aa4-d70bd5867c7c@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox