Re: sql

From: "Karthikeyan Sundaram" <skarthi98(at)hotmail(dot)com>
To: shyjukoyyam(at)gmail(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: sql
Date: 2007-02-06 07:16:51
Message-ID: BAY131-F50913AE1980E2A706ED12B09F0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

try this:

select entry_user_id, sum(decode(entry_user_id,'VC',1,0) as vc,
sum(decode(entry_user_id,'VE',1,0) as ve,
sum(decode(entry_user_id,'CV',1,0) as cv,
sum(decode(entry_user_id,'SC',1,0) as SC
from vigilance_master group
where entry_user_id=78
group by entry_user_id

>From: "Shyju Narayanan" <shyjukoyyam(at)gmail(dot)com>
>To: pgsql-sql(at)postgresql(dot)org
>Subject: [SQL] sql
>Date: Fri, 2 Feb 2007 13:09:09 +0530
>
>Hi All
>
>this is my table ;
>| ID |entry_user_id_int | category_id_chv |
>----------------------------------------------
>| 1 | 78 | CV |
>----------------------------------------------
>| 2 | 78 | VC |
>----------------------------------------------
>| 3 | 78 | CV |
>----------------------------------------------
>| 4 | 78 | CV |
>----------------------------------------------
>| 5 | 78 | CV |
>----------------------------------------------
>| 6 | 78 | CV |
>----------------------------------------------
>| 7 | 78 | CV |
>----------------------------------------------
>| 8 | 78 | CV |
>----------------------------------------------
>| 9 | 78 | VE |
>----------------------------------------------
>| 10 | 78 | CV |
>----------------------------------------------
>| 11 | 78 | SC |
>----------------------------------------------
>
>WHEN "select entry_user_id_int, category_id_chv,count(category_id_chv) from
>vigilance_master group by category_id_chv,entry_user_id_int having"
>entry_user_id_int=78
>result is :
>
>ID entry_user_id_int category_id_chv count
>
>1 78 VC 1
>2 78 VE 1
>3 78 CV 8
>4 78 SC 1
>
>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

_________________________________________________________________
Get in the mood for Valentine's Day. View photos, recipes and more on your
Live.com page.
http://www.live.com/?addTemplate=ValentinesDay&ocid=T001MSN30A0701

In response to

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

Browse pgsql-sql by date

  From Date Subject
Next Message Penchalaiah P. 2007-02-06 08:41:37 Re: sql
Previous Message A. Kretschmer 2007-02-06 06:58:25 Re: Search a range of cases/records