| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | RPK <rpk(dot)general(at)gmail(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: SQL query to display like this |
| Date: | 2007-08-24 11:36:05 |
| Message-ID: | 46CEC2A5.9090706@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Joseph Krogh | 2007-08-25 15:10:57 | Returning array of IDs as a sub-query with group-by |
| Previous Message | RPK | 2007-08-24 10:42:55 | SQL query to display like this |