0

I am getting employee data from source which gives me 2 rows for same employee. 1st row has a salary and 2nd has commission. to identify if it is salary or commission I have got one Flag column.

Now I want to store it in single row in my target table, where I would have salary and commision as columns.

Pratik Mehta
  • 13
  • 1
  • 5

2 Answers2

0

Use conditional aggregation

select employee_id,max(case when flag=0 then salary end) as salary,
       max(case when flag=1 then commission end) as commission
from tablename
group by employee_id
Fahmi
  • 37,315
  • 5
  • 22
  • 31
0

try a chance maybe work

select employee_id,sum(salary)salary,sum(commission) from
 (select employee_id,0 as salary,commission from tblname where flag=1
    union all
  select  employee_id ,salary ,0 commission from tblname where flag=0
  )a
group by employee_id
ali azizan
  • 311
  • 2
  • 11