Search Postgresql Archives

Re: HELP, how to make this query.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jan 15, 2012 at 12:17 PM, plasmasoftware net <administrator@xxxxxxxxxxxxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux