I have created the below query -
select person_number
,sal.current_salary
,(CASE WHEN '2021-03-31' between to_char(sal.date_From ,'YYYY-MM-DD')
AND to_char(sal.date_to ,'YYYY-MM-DD')
THEN SALARY_AMOUNT
else
null
END) "2019_sal"
,(CASE WHEN '2020-03-31' between to_char(sal.date_From ,'YYYY-MM-DD')
AND to_char(sal.date_to ,'YYYY-MM-DD')
THEN SALARY_AMOUNT
else
null
END) "2020_sal"
,(CASE WHEN '2019-03-31' between to_char(sal.date_From ,'YYYY-MM-DD')
AND to_char(sal.date_to ,'YYYY-MM-DD')
THEN SALARY_AMOUNT
else
null
END) "2019_sal"
from per_all_people_f papf,
comp_salary sal
where papf.person_id = sal.person_id
and papf.person_number = :p_emp_number
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
This gives me output like -
Person_number Current_salary 2019_sal 2020_sal
10 292929
10 287226
10 300000
11 282726
11 278090
Is there anyway i can tweak the above query to give me the output like -
Person_number Current_salary 2019_sal 2020_sal
10 292929 287226 300000
11 282726 278090
I.e. get the data against and employee in a single row. Can I use any function for this ?
MAX(fieldname)around your 3 additional columns and then group by person_number.