title: Calculate salary difference between two rows in HIVE
body: <p>I have a table with below columns-</p>
  
  <pre><code>last_name,    first_name,  department,     salary    
  </code></pre>
  
  <p>I want to calculate list of employees who receive a salary less than 100, compared
  to their immediate employee with higher salary in the same department. I went to below answer- <a href="https://stackoverflow.com/questions/14648201/compute-differences-between-succesive-records-in-hadoop-with-hive-queries">Compute differences between succesive records in Hadoop with Hive Queries</a>    and tried but I think I am doing something wrong as I am new to HIVE.  </p>
  
  <p>Below is the query which I am running-   </p>
  
  <pre><code>select last_name,first_name, salary from emp where 
  100 = LEAD(salary,1) OVER(PARTITION BY department ORDER BY salary)-salary;
  </code></pre>
  
  <p>Please help me with the solution.</p>