Re: Query aid

Поиск
Список
Период
Сортировка
От Janning Vygen
Тема Re: Query aid
Дата
Msg-id 200412161221.16018.vygen@gmx.de
обсуждение исходный текст
Ответ на Query aid  (Roberto Fichera <kernel@tekno-soft.it>)
Ответы Re: Query aid
Список pgsql-sql
Am Donnerstag, 16. Dezember 2004 11:34 schrieb Roberto Fichera:
> Hi all,
>
> I have a table acct as (username, terminatedate, terminatecause)
> I would like to build a query which returns three columns orderd by data
> like:
>
> date_trunc( 'day', terminatedate ) | count(cause1) | count(cause2)
>
> where cause1/2 are two type of termination cause from the field
> terminatecause.
>
> for example acct table could be:
>
> user1|01/01/2004 01:01:01| error
> user2|01/01/2004 01:02:01| error
> user1|01/01/2004 02:00:01| normal
> user3|02/01/2004 10:00:01| normal
> user2|02/01/2004 10:10:01| error
>
> I would like to obtain:
>
> date          |normal| error
> 01/01/2004|      1  |   2
> 02/01/2004|      1  |   1

try something like this:

SELECT  date_trunc( 'day', terminatedate ) AS day,  SUM(   CASE      WHEN cause = 'error'      THEN 1     ELSE 0   END
)AS error_count, SUM(   CASE      WHEN cause = 'normal'      THEN 1     ELSE 0   END ) AS normal_count,
 
FROM acct AS acct1
GROUP BY day
ORDER BY day ASC;

kind regards,
janning


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

Предыдущее
От: Andreas Kretschmer
Дата:
Сообщение: Re: [despammed] question about index
Следующее
От: "D'Arcy J.M. Cain"
Дата:
Сообщение: Re: question about index