Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 25B109F97F6 for ; Fri, 24 Aug 2007 07:43:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 39773-02 for ; Fri, 24 Aug 2007 07:42:57 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 3E8AD9F993A for ; Fri, 24 Aug 2007 07:42:57 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IOWcx-0007Yk-Kv for pgsql-sql@postgresql.org; Fri, 24 Aug 2007 03:42:55 -0700 Message-ID: <12310093.post@talk.nabble.com> Date: Fri, 24 Aug 2007 03:42:55 -0700 (PDT) From: RPK To: pgsql-sql@postgresql.org Subject: SQL query to display like this MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: rpk.general@gmail.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/201 X-Sequence-Number: 29139 I have a table with records like this: Date EmpID ADCode ADAmount ------------------------------------------------- 01-Jul-07 101 GPF 150 01-Jul-07 102 GPF.ADV 100 01-Jul-07 103 GPF 200 01-jul-07 104 GPF 300 I want to show results like this using a single SQL query: Date EmpID GPF GPF.ADV ------------------------------------------------- 01-Jul-07 101 150 0 01-Jul-07 102 0 100 01-Jul-07 103 200 0 01-Jul-07 104 300 0 I tried: select PaySlipDate,EmpID, case ADCode when 'GPF' then ADAmount else 0 end GPF, case ADCode when 'GPF.ADV' then ADAmount else 0 end 'GPF.ADV' from EmpSalaryRecord It is showing like this: Date EmpID GPF GPF.ADV ----------------------------------------- 01-Jul-07 101 0 0 01-Jul-07 101 150 0 01-Jul-07 102 0 100 01-Jul-07 103 0 0 01-Jul-07 103 1000 0 01-Jul-07 103 0 1000 It is showing multiple records of each employee for each date. First a record with GPF and GPF.ADV both zero and then records with values. I want a single record for each date and employee. -- View this message in context: http://www.nabble.com/SQL-query-to-display-like-this-tf4322876.html#a12310093 Sent from the PostgreSQL - sql mailing list archive at Nabble.com.