title: Hive query with sum analytical function
body: <p>I have data in the below format in a hive table.</p>
  <p><img src="https://i.stack.imgur.com/yje8e.png" alt="enter image description here" /></p>
  <p>Can someone help me to write a hive query which will give me the below result.</p>
  <p><img src="https://i.stack.imgur.com/eKYe3.png" alt="enter image description here" /></p>
  <p>The Result is the sum of previous 6 months without skipping months.</p>
  <p>Here is the query I have tried, but it gives only the running totals.</p>
  <pre><code>SELECT t.key, 
         t.tran_date, 
         Date_add(Add_months(t.tran_date, 1), 1 - Day(Add_months(t.tran_date, 1))) 
         run_date, 
         month(t.tran_date) 
         month, 
         Year(t.tran_date) 
         year, 
         Sum(t.usd_amt) 
           OVER( 
             partition BY t.acct_key, Month(t.tran_date)) 
         current_month_agg_incoming_amt, 
         Sum(t.usd_amt) 
           OVER( 
             partition BY t.acct_key, Ceil(Month(t.tran_date) / 6.0) 
             ORDER BY Month(t.tran_date))
         Result
  FROM   transaction_denorm_hist_tmp1 t 
  order by tran_date desc; 
  </code></pre>
  <p><img src="https://i.stack.imgur.com/NxE8o.png" alt="enter image description here" /></p>