title: Max Date with WHERE and HAVING clauses- Teradata
body: <p>I have a single transaction table with acc_nbr, tran_nbr, tran_amt, tran_dt, and tran_typ.</p>
  
  <p>I need to find only acc_nbr where tran_typ = 'xx' and sum(tran_amt)&lt;0 and show the most recent tran_dt.</p>
  
  <p>I can find all accounts where the sum of the 'xx' tran_typ are less than zero, but I can't seem to get the date in there without adding all of the transactions that contain a negative tran_typ 'xx'.</p>
  
  <p>What works so far:</p>
  
  <pre><code>    SEL acc_nbr, SUM(tran_amount) as error
      FROM DATABASE.TRAN_TBL
  
      WHERE tran_typ = 'xx' 
      GROUP BY acc_nbr
      HAVING sum(tran_amt)&lt;0
  </code></pre>
  
  <p>How can I bring in the date of the latest transaction? </p>