title: SQL get employees who salary increased more than $1000 from 1999 to 2000
body: <p>Here is a table for salary table:
  emp_id, salary, from_date, to_date.</p>
  <p>from_date contains the date information about when a new salary starts, to_date contains the date information about when a new salary end.</p>
  <p>e.g.</p>
  <pre><code>emp_id, salary , from_date,  to_date.
  100,   1000,     2020-01-01, 2021-01-01
  100,   2000,     2021-01-01, 2022-01-01
  </code></pre>
  <p>this person's salary from 2020 to 2021 is 1000. and from 2021 to 2022, the salary became 2000 instead.</p>
  <p>This is what I have so far, can someone double-check since something seems off?</p>
  <p>Thanks in advance.</p>
  <pre><code>SELECT PrevSalaries1.emp_no, (CurrSalaries2.salary - PrevSalaries1.salary) as salarie_add
  FROM 
      (
      SELECT emp_no, salary
      FROM salaries s1 
      WHERE YEAR(s1.to_date) = '1999' 
      GROUP BY s1.emp_no
      HAVING s1.salary = min(s1.salary)
      )  PrevSalaries1
   JOIN
      (
      SELECT emp_no, salary
      FROM salaries s2
      WHERE s2.to_date &gt;= '2000-01-01' and s2.from_date &lt; '2000-01-01'
      GROUP BY s2.emp_no
      HAVING s2.salary = max(s2.salary)
      ) CurrSalaries2
  WHERE PrevSalaries1.emp_no = CurrSalaries2.emp_no
  AND CurrSalaries2.salary - PrevSalaries1.salary &gt; 1000;
  </code></pre>
  <p>this is link for code: <a href="https://i.stack.imgur.com/5kwdr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5kwdr.png" alt="enter image description here" /></a></p>
  <p>update1:
  I think its important to mention that people salary maybe change (increase or decrease)multiple times in a year. That is why i use min to get lowest salary in 1999. and highest salary in 2000. Hope this helps.</p>