SQL first_value and last_value
<p>This is Netezza, which runs a flavor of Postgres</p>

<p>I'm using the <code>first_value</code> and <code>last_value</code> window functions, which are giving different values and confusing me. </p>

<p>Here's the code I'm running:</p>

<pre><code>select
    a.emp_id
    , a.sequence
    , FIRST_VALUE(a.DEP_ID) OVER(PARTITION BY a.emp_id ORDER BY a.sequence) AS first_dept
    , LAST_VALUE(a.DEP_ID) OVER(PARTITION BY a.emp_id ORDER BY a.sequence) AS last_dept
    , FIRST_VALUE(a.sequence) OVER(PARTITION BY a.emp_id ORDER BY a.sequence) AS first_seq
    , LAST_VALUE(a.sequence) OVER(PARTITION BY a.emp_id ORDER BY a.sequence) AS last_seq
FROM
    tname a
WHERE
    1=1
    AND a.event_id IN (1, 2)
    AND a.emp_id=11111
</code></pre>

<p>For <code>emp_id = 1111</code> this returns 2 records. </p>

<pre><code>emp_id   SEQuence   FIRST_DEPT  LAST_DEPT   FIRST_SEQ   LAST_SEQ
90565520    1       200800      200800      1           1
90565520    10      200800      200932      1           10
</code></pre>

<p>I'm confused as to why <code>last_seq</code> is returning <code>1</code> instead of 10</p>