Re: Return select statement with sql case statement

Поиск
Список
Период
Сортировка
От Ron
Тема Re: Return select statement with sql case statement
Дата
Msg-id 3524c35d-e566-9bad-e4bd-d493f05f2d4d@gmail.com
обсуждение исходный текст
Ответ на Return select statement with sql case statement  (hmidi slim <hmidi.slim2@gmail.com>)
Ответы Re: Return select statement with sql case statement
Список pgsql-general
On 07/04/2018 07:48 AM, hmidi slim wrote:
> Hi,
> I need to use conditional expression in my query, So I want to make a 
> query like this:
> select numberOfPremiumDays
>             case  when numberOfPremiumDays = date_part('day', 
> ('2018-11-05'::timestamp) - ('2018-11-01'::timestamp)) then
>                 select product_id,
>                 price
>                 from product
>                 where occupation_type_id = 1
>                 group by product_id, occupation_type_id
>
> However, in the documentation I found that the return of case was a value, 
> not like in my case I want to return a select statement.
> How can I use a conditional expression in a sql query?
> Best Regards.

The CASE clause is used to return one of many choices.  Based on this 
example, you need to do this:

select numberOfPremiumDays,
        product_id,
        price
        from product
where occupation_type_id = 1
   and  numberOfPremiumDays = date_part('day', ('2018-11-05'::timestamp) - 
('2018-11-01'::timestamp))
group by product_id, occupation_type_id



-- 
Angular momentum makes the world go 'round.


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom van Tilburg
Дата:
Сообщение: Postgres sometimes stalling on 'percentile_cont'
Следующее
От: Andy Colson
Дата:
Сообщение: Re: pg_dump out of memory