title: Rolling 7 days Sum with multiple dimensions in Hive
body: <p>I have data like below and want to get (1) today's user numbers and (2) past 7 days' user numbers by the dimensions below. My query isn't returning the result I want. Can someone fix my Hive SQL code? </p>
  
  <p>e.g.) today = 8/9/2018 </p>
  
  <p>past 7 days = 8/2/2018 - 8/8/2018</p>
  
  <blockquote>
    <p>Dimension: date, website, country_id, product_id</p>
    
    <p>Metrics : user</p>
  </blockquote>
  
  <pre><code>SELECT 
               date, 
               website,
               country_id,
               product_id,
               SUM(user) AS today_users,
               SUM(user) OVER (
             PARTITION BY website, country_id, product_id 
             ORDER BY date ASC ROWS BETWEEN 8 PRECEDING AND 1 PRECEDING) as past_7D_users
             FROM  Table
      GROUP BY 
      date, website, country_id, product_id;
  </code></pre>
  
  <p>RawData: </p>
  
  <pre><code>    &gt;t_date  |website |country_id|product_id|users
      &gt;8/1/2018   Whatev.com  2     EFG        12 
      &gt;8/2/2018   Whatev.com  2     EFG        23
      &gt;8/3/2018   Whatev.com  2     EFG        34 
      &gt;8/4/2018   Whatev.com  2     EFG        13
      &gt;8/5/2018   Whatev.com  2     EFG        47 
      &gt;8/6/2018   Whatev.com  2     EFG        39
      &gt;8/7/2018   Whatev.com  2     EFG        17 
      &gt;8/8/2018   Whatev.com  2     EFG        34
      &gt;8/1/2018   Google.com  1     ABC        10 
      &gt;8/2/2018   Google.com  1     ABC        20
      &gt;8/3/2018   Google.com  1     ABC        30 
      &gt;8/4/2018   Google.com  1     ABC        14
      &gt;8/5/2018   Google.com  1     ABC        40 
      &gt;8/6/2018   Google.com  1     ABC        35
      &gt;8/7/2018   Google.com  1     ABC        15 
      &gt;8/8/2018   Google.com  1     ABC        32
  </code></pre>
  
  <p>Expected Outcome:</p>
  
  <pre><code>date      | website  |country_id|product_id|today_users|past_7D_users|
  2018-08-08|Google.com|   1      | ABC      | 32        |164          |
  2018-08-09|Whatev.com|   2      | EFG      | 34        |185          |
  </code></pre>