title: How to get previous row values Teradata
body: <p>I have the data in the following format</p>
  <pre><code> Id    Code    Date         Amount       Type
   101   B25     5/4/2020      $500         C
   101   A15     5/5/2020      $100         D
   101   D15     5/5/2020      $200         D
   102   B35     6/2/2020      $400         C
   102   A15     6/2/2020      $50          D
  </code></pre>
  <p>I need the following</p>
  <pre><code> Id    Code    Date         Amount       Type  C_Date          C_Amount
   101   A15     5/5/2020      $100         D    5/4/2020         $500
   102   A15     6/2/2020      $50          D    6/2/2020         $400
  </code></pre>
  <p>For all Code='A15' I need Date and amount from previous row where Type='C'</p>
  <p>I did this</p>
  <pre><code> Select id, Amount, Date,
    sum(Amount) over (partition by ID ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as 
     C_Amount,
    Max(Date) over (partition by ID ROWS between UNBOUNDED PRECEDING and CURRENT ROW) as 
     C_Date
   from Table
   where code='A15' or Type='C'
  </code></pre>
  <p>Output is not the desired one</p>
  <pre><code> Id    Code    Date         Amount       Type  C_Date          C_Amount
   101   A15     5/5/2020      $100         D    ***5/5/2020         $100***
   102   A15     6/2/2020      $50          D    ***6/2/2020         $50***
  </code></pre>
  <p>Any help is appreciated</p>