Last answered:

22 May 2024

Posted on:

19 Feb 2023

1

Ranking Window Functions and Joins

Can a solution for question 2 in this assignment be this:


SELECT

    e.emp_no,

    DENSE_RANK() OVER w as employee_salary_ranking,

    s.salary,

    e.hire_date,

    s.from_date,

    (YEAR(s.from_date) - YEAR(e.hire_date)) AS years_from_start

FROM

employees e

JOIN

    salaries s ON s.emp_no = e.emp_no

WHERE e.emp_no BETWEEN 10500 AND 10600

    AND YEAR(s.from_date) - YEAR(e.hire_date) >= 5

WINDOW w as (PARTITION BY e.emp_no ORDER BY s.salary DESC);


The difference between this and the provided solution is the position of the AND clause. Here is it in the WHERE statement instead of the JOIN

1 answers ( 0 marked as helpful)
Instructor
Posted on:

22 May 2024

0

Hi Cyd-Marie!

Thanks for reaching out!


Your solution is correct. It does not matter that you used the AND operator at another position. It is important to include this condition in order to obtain the correct result set.


Hope this helps.
Best,
Martin

Submit an answer