Resolved: SQL query Code Clarification
the problem statement was to find the average salary. the SQL code mentioned here queries the year from from_date data. Is this data considered for the subsequent years till the employee is present in the database as this salary value will have an effect on averaging. What happens when the unique emp_no remains, but the salary is incremented? Also what if the employees leaves after some years, then we should consider to_date data also?
Thanks for reaching out.
Your questions are all on point. Knowing the data stored in the employees_mod database should help you better figure out how to answer these questions.
Here are some hints.
- We use the YEAR() function to specify which calendar years we will be obtaining data for.
- Yes, data for the obtained calendar year values will be taken into consideration while estimating the relevant average value.
- When the salary value increases, the employee number remains the same - the employee number is a primary key in the database.
- If the employee has left, then there will be no calendar year value(s) obtained for the subsequent year(s) in the calculation.
Hope this helps.