From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: sql
Date: Tue, 6 Feb 2007 07:41:40 +0100
Message-ID: <20070206064140.GA6761@a-kretschmer.de> (raw)
In-Reply-To: <fecb4bb00702012339t135143d8v42e5cd6c834fca09@mail.gmail.com>
References: <fecb4bb00702012339t135143d8v42e5cd6c834fca09@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: andreas.kretschmer@schollglas.com
Subject: Re: sql
In-Reply-To: <20070206064140.GA6761@a-kretschmer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox