pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: RPK <rpk.general@gmail.com>
To: pgsql-sql@postgresql.org
Subject: SQL query to display like this
Date: Fri, 24 Aug 2007 03:42:55 -0700 (PDT)
Message-ID: <12310093.post@talk.nabble.com> (raw)


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.




view thread (2+ messages)  latest in thread

Message-ID: <12310093.post@talk.nabble.com>
Permalink:  ../12310093.post@talk.nabble.com/
Also on:    postgresql.org/message-id/12310093.post@talk.nabble.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rpk.general@gmail.com
  Subject: Re: SQL query to display like this
  In-Reply-To: <12310093.post@talk.nabble.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