Re: SQL - Mailing list pgsql-novice

From Manfred Koizar
Subject Re: SQL
Date
Msg-id cei1tu0jie10b3agged3l539v6s6k4op08@4ax.com
Whole thread Raw
In response to SQL  ("cristi" <cristi@dmhi.ct.ro>)
List pgsql-novice
On Tue, 12 Nov 2002 08:45:37 +0200, "cristi" <cristi@dmhi.ct.ro>
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: "cristi"
Date:
Subject: Re: SQL
Next
From: Setyo Nugroho
Date:
Subject: Delete column