We have an EmployeeSalary Table which holds information about Employee and the Salary which the Employee is getting in respective months. Below is the snapshot of the EMP_SAL table:
Now we need to write an SQL Query which can retrieve EMPLOYEE ID,EMPLOYEE NAME, CURRENT MONTH, CURRENT MONTH SALARY and PREVIOUS MONTH SALARY of the EMPLOYEE. If the SALARY for any particular month is not available then it should be treated as ZERO.
Below is the Output which is required from the SQL Query:
Can you write the correct query? Leave your SQL Query as comment below. There may be several ways of getting the desired output. You can check the answer on ANSWERS PAGE too. However for better understanding of Teradata SQL , it is suggested that you leave a comment below with your SQL Query and then check our answer. We may get better and more ways of getting the result.
Hint: Try it via self join