I have to write a query and check whether sales has increased (use yes) and decreased (use no in column SaleIncreased) for every salesman compared to his previous year's performance.
sample table output should be as follows
EmpID salesman year SaleIncreased
7843921 John 2016 Null
7843921 John 2017 Yes
7843934 Neil 2016 Null
7843934 Neil 2017 No
I have used self join with CASE WHEN statement as follows
select t1.empid, t1.salesman, t1.year
from Sales_temp as t1
inner join Sales_temp as t2
on t1.empid = t2.empid and t2.year = t1.year - 1
case when t1.sale > t2.sale
then 'Yes'
else 'No'
end as 'SaleIncreased'
I'm unable to get the desired output.