Re: sql

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: sql
Date: 2007-02-06 06:41:40
Message-ID: 20070206064140.GA6761@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am Fri, dem 02.02.2007, um 13:09:09 +0530 mailte Shyju Narayanan folgendes:
> Hi All
>
>
> BUT I NEED THE RESULT AS
> entry_user_id_int COUNT(VC) COUNT(VE) COUNT(CV) COUNT(SC) TOTAL
> 78 1 1 8 1 11
>

You need something like this (i called the table foo and without the
sc-column):

select entry_user_id_int,
sum(case when category_id_chv = 'VC' then 1 else 0 end) as "count(vc)",
sum(case when category_id_chv = 'VE' then 1 else 0 end),
sum(case when category_id_chv = 'CV' then 1 else 0 end),
sum(1)
from foo
where entry_user_id_int = 78
group by entry_user_id_int;
entry_user_id_int | count(vc) | sum | sum | sum
-------------------+-----------+-----+-----+-----
78 | 1 | 1 | 8 | 11

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

  • sql at 2007-02-02 07:39:09 from Shyju Narayanan

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2007-02-06 06:58:25 Re: Search a range of cases/records
Previous Message Tom Lane 2007-02-05 21:49:10 Re: Symbol lookup error