title: Multiple and count rows in SQL
body: <p>I have table with warehouse intakes and outtakes. I want to multiple rows to every day and then count and sum storage cost to every day. (<a href="https://i.stack.imgur.com/h8GCl.png" rel="nofollow noreferrer">Original Image</a>)</p>
  
  <pre><code>+ -------- + -------------- + ---------- + ---------- + -------------- + ------------ +
  | material | wasting_time_a | indate     | outdate    | count_material | storage_cost |
  + -------- + -------------- + ---------- + ---------- + -------------- + ------------ +
  | 963651   | 5              | 2016-12-02 | 2016-12-06 | 2              | 0.04357      |
  | 963651   | 6              | 2016-12-02 | 2016-12-07 | 1              | 0.02615      |
  | 963651   | 7              | 2016-12-02 | 2016-12-08 | 1              | 0.0305       |
  | 963651   | 11             | 2016-12-02 | 2016-12-12 | 4              | 0.1917       |
  | 963651   | 12             | 2016-12-02 | 2016-12-13 | 1              | 0.05229      |
  | 963651   | 13             | 2016-12-02 | 2016-12-14 | 3              | 0.1699       |
  | 963651   | 14             | 2016-12-02 | 2016-12-15 | 9              | 0.5490       |
  | 963651   | 15             | 2016-12-02 | 2016-12-16 | 7              | 0.4575       |
  | 963651   | 16             | 2016-12-02 | 2016-12-17 | 2              | 0.1394       |
  | 963651   | 18             | 2016-12-02 | 2016-12-19 | 5              | 0.3922       |
  | 963651   | 19             | 2016-12-02 | 2016-12-20 | 6              | 0.4968       |
  | 963651   | 20             | 2016-12-02 | 2016-12-21 | 6              | 0.5229       |
  | 963651   | 21             | 2016-12-02 | 2016-12-22 | 2              | 0.1830       |
  | 963651   | 22             | 2016-12-02 | 2016-12-23 | 1              | 0.0959       |
  | 963651   | 2              | 2016-12-22 | 2016-12-23 | 2              | 0.01743      |
  | 963651   | 9              | 2016-12-22 | 2016-12-30 | 3              | 0.1177       |
  | 963651   | 10             | 2016-12-22 | 2016-12-31 | 1              | 0.04357      |
  | 963651   | 12             | 2016-12-22 | 2017-01-02 | 1              | 0.05229      |
  | 963651   | 14             | 2016-12-22 | 2017-01-04 | 2              | 0.1220       |
  + -------- + -------------- + ---------- + ---------- + -------------- + ------------ +
  </code></pre>
  
  <p>Waiting_time_a is just diff between indate and outdate. Count_material is count of material outtaken from warehouse on outdate.</p>
  
  <p>Storage costs increase every day, so I need to count each day specifically. My idea is to count each day this way: I multiple rows from indate to outdate for each row and in the end I will sum it. Based on my table storage costs for 2016-12-02 will be SUM of count_material group by indate. But I don't know how to count it for 2016-12-03.</p>
  
  <p>I am using Impala, but every SQL will help :)</p>
  
  <p>Table will like:  </p>
  
  <pre><code>+ ---------- + ------------------ +
  | DATE       | total_storage_cost |
  + ---------- + ------------------ +
  | 2016-12-02 | 40                 |
  | 2016-12-03 | 47                 |
  | 2016-02-04 | ...                |
  | 2016-02-05 | ...                |
  | 2016-02-06 | ...                |
  + ---------- + ------------------ +
  </code></pre>
  
  <p>Thank you for your help</p>