Re: SQL query to display like this

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: SQL query to display like this
Дата
Msg-id 46CEC2A5.9090706@archonet.com
обсуждение исходный текст
Ответ на SQL query to display like this  (RPK <rpk.general@gmail.com>)
Список 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: RPK
Дата:
Сообщение: SQL query to display like this
Следующее
От: Andreas Joseph Krogh
Дата:
Сообщение: Returning array of IDs as a sub-query with group-by