Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvus7-0004Kl-5V for pgsql-sql@arkaria.postgresql.org; Thu, 06 Apr 2017 00:01:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cvus6-000647-IY for pgsql-sql@arkaria.postgresql.org; Thu, 06 Apr 2017 00:01:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cvus4-00061c-KY for pgsql-sql@postgresql.org; Thu, 06 Apr 2017 00:01:52 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cvus1-0002qq-Mw for pgsql-sql@postgresql.org; Thu, 06 Apr 2017 00:01:52 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6476620A5A; Wed, 5 Apr 2017 20:01:48 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 05 Apr 2017 20:01:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=3mh4SpplKD9sFFUvw1 bwPosdLvq/h/5OWDKjzDQrG3M=; b=ZTaUoIHMy4ABbQba5Zx9MN+IIh0l9Mkzvj uhqur4g2BMdnPO1LP58G506ibE0Sux354wzry4xg+jUeRfbnc2JaXrXEJQ0MBIEP NaFaOZfK1b0k8u/+xbkHLPcFERMXEV/PpLzdg/zC5LOIXQntwwjJs57nSa/PLOsl mq0vSLsd8qo7tErlskmqbmxCaoPrfPKukCXQXIawGbXfQzuHcHnHRTqooh3qhN/E suQ5ePMwracmngOxyOa6p4DkdQkYlGT94DHr/lHerrN4TnNkrXd9LQflFw4zex8+ UsieeJ05Zrh1Rx+cWdGTcoP/xWphFtHIO/UGGN7J5yIyU9XFO4gQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=3mh4SpplKD9sFFUvw1bwPosdLvq/h/5OWDKjzDQrG3M=; b=Iof9QEr7 Jd6nhRMODnNBLNmuvGrd5TETqAI3kCUDfbxYVO/sEahaMixlLQB5M15YIuWvvsII 3EH+/hPVq03wHHWFMkdt77dg8YuKOKQtktBryuKd7FbXy1rT4qUN1VIRWGlHLz5g jIHLZbqzt1g694aIfclwlpeWwORi1vgjq94M0BGlbAb/ZkIavB7PnToCRyoQfMuK N/oG1bkz+fu2lziuDBfQTrwQqkuYMCgJxAUVHpdrgkU3ZIn0ZbXeeJVPEaFRjMOR ThVlyMFgzjBquSlQrucRiGMbGVdLchEkBwr+4JY3xKEU+BfkNIk9MFUeFSKfrESR YiN+PsmpcPiX2A== X-ME-Sender: X-Sasl-enc: wIZeRLnyDaJ/+aB+44Csvxi0+kZ+P0mDAP/o6KG/SJR0 1491436908 Received: from [192.168.1.2] (97-113-63-158.tukw.qwest.net [97.113.63.158]) by mail.messagingengine.com (Postfix) with ESMTPA id E043424370; Wed, 5 Apr 2017 20:01:47 -0400 (EDT) From: Adrian Klaver Subject: Re: Crosstab function To: Gowtham Vel References: Cc: pgsql-sql@postgresql.org Message-ID: <270d8a50-574e-74b7-d487-50ad17725df9@aklaver.com> Date: Wed, 5 Apr 2017 17:01:47 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 04/05/2017 10:04 AM, Gowtham Vel wrote: > Hi Adrian, > > Could you please check and update on my below email This would have happened sooner with a self contained test case e.g. a CREATE TABLE statement and COPY/INSERT statements for the data. At any rate: test=# \d crosstab_test Table "public.crosstab_test" Column | Type | Modifiers --------+-------------------+----------- id | integer | wf_id | character varying | name | character varying | value | character varying | I lower cased the name values in the above. Showing a small subset of the 80 some names you have: SELECT * FROM crosstab ('select wf_id, name, value from crosstab_test where name in(''interchangecontrolnumber'', ''ponumber'', ''docid'',''direction'', ''docdate'') order by 1', 'select distinct name from crosstab_test where name in(''interchangecontrolnumber'', ''ponumber'', ''docid'', ''direction'', ''docdate'') order by 1') AS ( wf_id INT, direction VARCHAR, docdate VARCHAR, docid VARCHAR, interchange VARCHAR, po VARCHAR); -[ RECORD 1 ]---------------------- wf_id | 1627075 direction | Inbound docdate | 20170316 docid | 411069802 interchange | 2947 po | 411069802 -[ RECORD 2 ]---------------------- wf_id | 1652040 direction | Outbound docdate | 20170319 docid | 201703191489929516706 interchange | 7167 po | NULL For more information see: https://www.postgresql.org/docs/9.5/static/tablefunc.html F.36.1.4. crosstab(text, text) > > Thanks > Gowtham K > > > On Apr 4, 2017 11:58 PM, "Gowtham Vel" > wrote: > > Hi Adrian, > > I have attached the input table and output table in below .xlsx sheet > > 1) I have removed the duplicate rows and sort the INPUT_TABLE i.e., > SELECT * FROM "public".INPUT_TABLE ORDER by 2,3 > 2) Input_table column name should be the column heading for > Output_table. > 3) Input_table column value should be the rows for Output_table. > 4) some values i have mention in null , because its for future > record(its might come) > 5) please refer the below attached sheet and provide your assistance, > > Regards, > Gowtham K > -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql