Re: HELP, how to make this query. - Mailing list pgsql-general

From Raghavendra
Subject Re: HELP, how to make this query.
Date
Msg-id CA+h6Ahg+rK41XXM7kVp3x2fXEPW1gY7qDeyBm-TRRD1KN8-1cw@mail.gmail.com
Whole thread Raw
In response to HELP, how to make this query.  (plasmasoftware net <administrator@plasmasoftware.net>)
List pgsql-general
On Sun, Jan 15, 2012 at 12:17 PM, plasmasoftware net <administrator@plasmasoftware.net> wrote:
select j.kode_barang kode_barang,j.isi_Satuan from J_master_barang j order by j.kode_barang asc
display 
kode                 isi
00000000000001 24
00000000000001B 12
00000000000001C 1

i want to make that become when i select my table.how to make this.

kode                       isi_A     isi_B    isi_C
00000000000001  24        12        1

I think you have to use crosstab, you can try this out...

select '000000000001' as Kode, sum(case when j.kode_barang='A' then isi else 0 end) as isi_A,
                                               sum(case when j.kode_barang='B' then isi else 0 end) as isi_B,
                                               sum(case when j.kode_barang='C' then isi else 0 end) as isi_C from j_master_barang; 

---
Regards,
Raghavendra
EnterpriseDB Corporation

pgsql-general by date:

Previous
From: plasmasoftware net
Date:
Subject: HELP, how to make this query.
Next
From: David Waddy
Date:
Subject: Re: How to return latest results without a polygon intersect?