title: SQL - LAG but skip specific rows based on value?
body: <p>I have the below table. What I am trying to do is add a LAG column which shows me the previous [EndDate] for ONLY entries that have a status that isn't 6. 6 means inactive.. so I don't want to count them.</p>
  <pre><code>SPID        ID            Status       StartDate                 EndDate   
  29333       102             7         01 jan 2013              1 Jan 2014
  29333       202             6         7 Jun 2021               15 Jun 2022
  29333       384             6         10 jun 2021              17 jun 2022
  29333       532             2         8 oct 2023               10 oct 2025
  </code></pre>
  <p>I have used a LAG function which works but not sure how I could amend this to skip the rows I don't need? My ideal output would look like this..</p>
  <pre><code>SPID        ID            Status       StartDate                 EndDate           PrevED
  29333       102             7         01 jan 2013              1 Jan 2014        01-Jan-1900  
  29333       202             6         7 Jun 2021               15 Jun 2022       1-Jan-2014
  29333       384             6         10 jun 2021              17 jun 2022       1-Jan-2014
  29333       532             2         8 oct 2023               10 oct 2025       1-Jan-2014
  </code></pre>
  <p>Any tips on the best way of achieving this?</p>