pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hengky Liwandouw <hengkyliwandouw@gmail.com>
To: 'pgsql-general General' <pgsql-general@postgresql.org>
Subject: Crosstab function
Date: Mon, 5 May 2014 14:49:31 +0800
Message-ID: <000601cf682e$2dce68c0$896b3a40$@com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-general>

Hi Friends, 

 

Could somebody help me with crosstab function ?  I have warehouse table:

 

CREATE TABLE tblwarehouse (

    id integer NOT NULL,

    warehousename character varying(20)

);

 

COPY tblwarehouse (id, warehousename) FROM stdin;

2     OFFICE

3     STORE2

\.

 

And product table :

 

CREATE TABLE tblproduct (

    id serial NOT NULL,

    produkid text,

    warehouseid integer,

    onhand integer

);

 

COPY tblproduct (produkid, warehouseid, onhand) FROM stdin;

2791404000014     2     10

2791404000021     3     10

2791404000014     3     45

\.

 

I need crosstab function to display record from tblproduct like this :

 

   PRODUKID    | OFFICE | STORE2 | TOTAL

---------------+--------+--------+ ------

 2791404000014 |     10 |     45 |   55

 2791404000021 |      0 |     10 |   10

 

The crosstab warehouse column name (OFFICE & Store2) is taken from
tblwarehouse so when user add warehouse, crosstab column name will change
automatically. And also each row has total qty.

 

 

 

Thanks in advance !

 

view thread (23+ messages)  latest in thread

Message-ID: <000601cf682e$2dce68c0$896b3a40$@com>
Permalink:  ../000601cf682e$2dce68c0$896b3a40$@com/
Also on:    postgresql.org/message-id/000601cf682e$2dce68c0$896b3a40$@com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hengkyliwandouw@gmail.com
  Subject: Re: Crosstab function
  In-Reply-To: <000601cf682e$2dce68c0$896b3a40$@com>
  References: <000601cf682e$2dce68c0$896b3a40$@com>

* 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