Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 065819F99D7 for ; Fri, 24 Aug 2007 08:38:10 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 65060-06 for ; Fri, 24 Aug 2007 08:38:02 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 984BF9F99D0 for ; Fri, 24 Aug 2007 08:38:06 -0300 (ADT) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 1C64E55488; Fri, 24 Aug 2007 12:36:06 +0100 (BST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 04770274054; Fri, 24 Aug 2007 12:36:06 +0100 (BST) Message-ID: <46CEC2A5.9090706@archonet.com> Date: Fri, 24 Aug 2007 12:36:05 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: RPK Cc: pgsql-sql@postgresql.org Subject: Re: SQL query to display like this References: <12310093.post@talk.nabble.com> In-Reply-To: <12310093.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/202 X-Sequence-Number: 29140 RPK wrote: > 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. No it's not. It's showing 2 records for empid=101, 3 for empid=103 but only 1 for empid=102. That says to me you have multiple rows in your table for each (date,empid) combination. If you want to eliminate them, either filter on AdCode or perhaps SUM() your GPF/GPF.ADV colums. -- Richard Huxton Archonet Ltd