Re: SQL - Mailing list pgsql-novice

From cristi
Subject Re: SQL
Date
Msg-id 002501c28a39$b49c3420$7201a8c0@aaa
Whole thread Raw
In response to Cancelling long running query?  ("Patrick Hatcher" <PHatcher@macys.com>)
List pgsql-novice
Amazing!
Brilliant solution!
You make me very  happy!

Thanks!

> wrote:
> >This is the contents of the table:
> >marca     mo
> >1            C
> >2            C
> >[...]
> >
> >I need a SQL interogation with following results:
> >marca concedii boala obligatii
> >  1         2           1        0
> >  2         1            0       0
> >  4         0            1       0
> >  5         0            0       1
>
> SELECT marca,
>        SUM(CASE mo WHEN 'C' THEN 1 ELSE 0 END) AS concedii,
>        SUM(CASE mo WHEN 'B' THEN 1 ELSE 0 END) AS boala,
>        SUM(CASE mo WHEN 'O' THEN 1 ELSE 0 END) AS obligatii
>   FROM yourtable
>  GROUP BY marca
>  ORDER BY marca;
>
> HTH.
> Servus
>  Manfred
>


pgsql-novice by date:

Previous
From: "Henshall, Stuart - Design & Print"
Date:
Subject: Re: Delete column
Next
From: "Simon Kelly"
Date:
Subject: oidin error when parsing XML documents