Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WhCih-0006dT-7p for pgsql-general@arkaria.postgresql.org; Mon, 05 May 2014 06:49:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WhCig-0004XU-No for pgsql-general@arkaria.postgresql.org; Mon, 05 May 2014 06:49:46 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WhCie-0004XL-Uo for pgsql-general@postgresql.org; Mon, 05 May 2014 06:49:45 +0000 Received: from mail-pd0-x22d.google.com ([2607:f8b0:400e:c02::22d]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WhCib-0006ch-MD for pgsql-general@postgresql.org; Mon, 05 May 2014 06:49:44 +0000 Received: by mail-pd0-f173.google.com with SMTP id y10so4108586pdj.4 for ; Sun, 04 May 2014 23:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :thread-index:content-language; bh=C+9mIG80OLlC38sGzQ7lH15YzI/jc438vBV+bdl6UO4=; b=MhPMyQTHVTR/ZMioSZ/rajjXGA6U1h49ODIKmRGqDmnTGSGnXnEn8k118UxsLTtrZX AfyV6gKrxd6t73TNrXvux53NZ7R1GLc4QTC68yssMlYJ/XlwNW0kIi1+7iVJxqOdDHhu Pdopisa2SYB0QfbNxOAHgITK5VMCQlk/rTofsXMT9/ptqU2pUCguWM6oAdIr5AVkQbBW h7McZLUIcbBTjAcXFf8qvNfdqCuRJrnly1qz8uPK1MCkEpQ9O0Rv6mWqeEYQvNH8Ko/2 qKwXC3V8i7yKwwxfulevGA95RYudWwF78TShzjYPHv0J08pFYwR4MUYTw1IL4MVXVLPk FFMQ== X-Received: by 10.66.164.70 with SMTP id yo6mr26153145pab.85.1399272579732; Sun, 04 May 2014 23:49:39 -0700 (PDT) Received: from hplPC ([180.251.162.119]) by mx.google.com with ESMTPSA id qh2sm63484945pab.13.2014.05.04.23.49.36 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 May 2014 23:49:38 -0700 (PDT) From: "Hengky Liwandouw" To: "'pgsql-general General'" Subject: Crosstab function Date: Mon, 5 May 2014 14:49:31 +0800 Message-ID: <000601cf682e$2dce68c0$896b3a40$@com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01CF6871.3BF1A8C0" X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac9oLiqh6V32/mb4TD+Pp855gSVedw== Content-Language: en-us X-Pg-Spam-Score: 0.7 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org This is a multipart message in MIME format. ------=_NextPart_000_0007_01CF6871.3BF1A8C0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 ! ------=_NextPart_000_0007_01CF6871.3BF1A8C0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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 !

 

------=_NextPart_000_0007_01CF6871.3BF1A8C0--