Skip site navigation (1) Skip section navigation (2)

Re: SQL

From: Manfred Koizar <mkoi-pg(at)aon(dot)at>
To: "cristi" <cristi(at)dmhi(dot)ct(dot)ro>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: SQL
Date: 2002-11-12 09:28:46
Message-ID: cei1tu0jie10b3agged3l539v6s6k4op08@4ax.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Tue, 12 Nov 2002 08:45:37 +0200, "cristi" <cristi(at)dmhi(dot)ct(dot)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

In response to

  • SQL at 2002-11-12 06:45:37 from cristi

Responses

  • Re: SQL at 2002-11-12 10:53:15 from cristi

pgsql-novice by date

Next:From: Setyo NugrohoDate: 2002-11-12 09:56:58
Subject: Delete column
Previous:From: cristiDate: 2002-11-12 09:14:09
Subject: Re: SQL

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group