Обсуждение: sql

Поиск
Список
Период
Сортировка

sql

От
"Shyju Narayanan"
Дата:
Hi All<br /><br /> this is my table ;<br />| ID    |entry_user_id_int  | category_id_chv |<br
/>----------------------------------------------<br/>| 1        |        78            |    CV              |<br
/>----------------------------------------------<br />| 2        |        78            |    VC              |<br
/>----------------------------------------------<br/>| 3        |        78            |    CV            |<br
/>----------------------------------------------<br/> | 4        |        78            |    CV            |<br
/>----------------------------------------------<br/>| 5        |        78            |    CV            |<br
/>----------------------------------------------<br/>| 6        |        78            |    CV            | <br
/>----------------------------------------------<br/>| 7        |        78            |    CV            |<br
/>----------------------------------------------<br/>| 8        |        78            |    CV            |<br
/>----------------------------------------------<br />| 9        |        78            |    VE            |<br
/>----------------------------------------------<br/>| 10    |        78            |    CV            |<br
/>----------------------------------------------<br/>| 11    |        78            |    SC            | <br
/>----------------------------------------------<br/><br />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<br />result is :<br /><br />ID   entry_user_id_int  category_id_chv count <br /><br />1       
78                      VC                     1<br />2        78                       VE                     1<br
/>3       78                       CV                     8 <br />4        78                       SC       
            1<br /><br />BUT I NEED THE RESULT AS <br />entry_user_id_int     COUNT(VC)  COUNT(VE)  COUNT(CV)  
COUNT(SC) TOTAL<br /> 78        1 1 8 1 11<br /><br /><br /><br /><br /> 

Re: sql

От
"A. Kretschmer"
Дата:
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


Re: sql

От
"Karthikeyan Sundaram"
Дата:
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@gmail.com>
>To: pgsql-sql@postgresql.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



Re: sql

От
"Penchalaiah P."
Дата:
Hi...
I tried this its working.. can u please check this.

select count(*) as all, sum(decode(entry_user_id,'VC',1)) as
entry_user_id,sum(decode(entry_user_id,'VE',1)) as VE
,sum(decode(entry_user_id,CV,1))as
CV,sum(decode(entry_user_id,'SC',1))as SC from vigilance_master;


regards
penchal

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Karthikeyan
Sundaram
Sent: Tuesday, February 06, 2007 12:47 PM
To: shyjukoyyam@gmail.com; pgsql-sql@postgresql.org
Subject: Re: [SQL] 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@gmail.com>
>To: pgsql-sql@postgresql.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


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
              http://archives.postgresql.org

Information transmitted by this e-mail is proprietary to Infinite Computer Solutions and / or its Customers and is
intendedfor use only by the individual or the entity to which it is addressed, and may contain information that is
privileged,confidential or exempt from disclosure under applicable law. If you are not the intended recipient or it
appearsthat this mail has been forwarded to you without proper authority, you are notified that any use or
disseminationof this information in any manner is strictly prohibited. In such cases, please notify us immediately at
info.in@infics.comand delete this email from your records.