Re: sql - Mailing list pgsql-sql

From A. Kretschmer
Subject Re: sql
Date
Msg-id 20070206064140.GA6761@a-kretschmer.de
Whole thread Raw
In response to sql  ("Shyju Narayanan" <shyjukoyyam@gmail.com>)
List 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


pgsql-sql by date:

Previous
From: sneumann
Date:
Subject: PL/pgsql declaration of string / bit / number with given (variable!) length
Next
From: "A. Kretschmer"
Date:
Subject: Re: Search a range of cases/records