title: How to write a SQL query with minimum and maximum salary from each department by date?
body: <p>I have a table like below:</p>
  
  <pre><code> dept  | salary | year
   ------+--------+-----
   HR    | 1000   | 2014
   Acc   | 2000   | 2014
   Acc   | 1000   | 2015
   Acc   | 3000   | 2015
   Dev   | 5000   | 2015
  </code></pre>
  
  <p>I want to find the department having minimum and maximum salary which is grouped by a year. The expected output is as follows:</p>
  
  <pre><code>year | min_sal_dept | max_sal_dept
  -----+--------------+-----
  2014     HR             Acc
  2015     Acc            Dev
  </code></pre>
  
  <p>How can I write a SQL query for getting output in such a way?    </p>