title: Hive/SQL How do you access the value of the column which you just computed for previous rows?
body: <p>I have a table <code>uv_user_date</code> looks like this:
  <a href="https://i.stack.imgur.com/14ia6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/14ia6.png" alt="enter image description here" /></a></p>
  <p>Its basically a <code>user log in table</code> which shows the cumulative login days partition by user_id.
  And the column <code>pre</code> show the last login date of a user login record.</p>
  <p>Based on this I want to compute the consecutive login days for each user record.</p>
  <p>The answer should be :
  <a href="https://i.stack.imgur.com/hhPOk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hhPOk.png" alt="enter image description here" /></a>
  My idea is : for a record</p>
  <ul>
  <li>if(uv_date - pre = 1 day)
  <ul>
  <li>then consecutive login days is the last consecutive login days + 1</li>
  </ul>
  </li>
  <li>else
  <ul>
  <li>1
  but I am having trouble with accessing the <code>last consecutive login days</code> value.</li>
  </ul>
  </li>
  </ul>
  <p>The Code would be:</p>
  <pre><code>SELECT *,
     if(pre = date_add(uv_date, -1), last(consecutive_days) + 1, 1) consecutive_days
  FROM uv_user_date
  </code></pre>
  <p>Is there any way to get the value of <code>last(consecutive_days)</code></p>