title: How to set flag for row except last in SQL
body: <p>How to set flag for each row based on ROW_NUMBER() except last row?</p>
  
  <p>Data Table(events):</p>
  
  <pre><code>+-----+-------------+-----------+----------+----------+
  | Ref |   E_Date    |   Item    | Customer | Assignee |
  +-----+-------------+-----------+----------+----------+
  |   1 | 10/10/2017  | Microsoft | DIB      | Jeffry   |
  |   2 | 10/11/2017  | Oracle    | UNB      | Asif     |
  |   3 | 10/12/2017  | IBM       | UNB      | John     |
  |   4 | 10/13/2017  | Microsoft | DIB      | Asif     |
  |   5 | 10//14/2017 | Oracle    | UNB      | Jeffry   |
  |   6 | 10/15/2017  | SAP       | DIB      | Said     |
  |   7 | 10/15/2017  | Microsoft | DIB      | Said     |
  +-----+-------------+-----------+----------+----------+
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>+-----+------------+-----------+----------+----------+------+
  | Ref |   E_Date   |   Item    | Customer | Assignee | Flag |
  +-----+------------+-----------+----------+----------+------+
  |   1 | 10/10/2017 | Microsoft | DIB      | Jeffry   |    1 |
  |   4 | 10/13/2017 | Microsoft | DIB      | Asif     |    1 |
  |   7 | 10/15/2017 | Microsoft | DIB      | Said     |    0 |
  |   2 | 10/11/2017 | Oracle    | UNB      | Asif     |    1 |
  |   5 | 10/14/2017 | Oracle    | UNB      | Jeffry   |    0 |
  +-----+------------+-----------+----------+----------+------+
  </code></pre>
  
  <p>My query:</p>
  
  <pre><code>SELECT * FROM
  (
      SELECT Ref, E_Date, Item, Customer,Assignee,
      COUNT(*) OVER (PARTITION BY Customer, Item) AS cnt,
      CASE WHEN (ROW_NUMBER() OVER(PARTITION BY Customer, Item ORDER BY Item)) = 1 
      THEN 1   ELSE 0    END Flag
      FROM Events        
  ) t
  WHERE cnt &gt; 1
  ORDER BY Item, Customer;
  </code></pre>
  
  <p>Please help me to get result like above expected result</p>