title: Calculating per day in SQL
body: <p>I have an sql table like that:</p>
  
  <pre><code>Id    Date     Price
  1  21.09.09     25
  2  31.08.09     16
  1  23.09.09     21
  2  03.09.09     12
  </code></pre>
  
  <p>So what I need is to get min and max date for each id and dif in days between them. It is kind of easy. Using SQLlite syntax:</p>
  
  <pre><code>  SELECT id, 
           min(date), 
           max(date), 
           julianday(max(date)) - julianday(min(date)) as dif 
    from table group by id
  </code></pre>
  
  <p>Then the tricky one: how can I receive the price per day during this difference period. I mean something like this:</p>
  
  <pre><code>ID Date      PricePerDay
  1  21.09.09      25
  1  22.09.09       0
  1  23.09.09      21
  2  31.08.09      16
  2  01.09.09       0
  2  02.09.09       0
  2  03.09.09      12
  </code></pre>
  
  <p>I create a cte as you mentioned with calendar but dont know how to get the desired result:</p>
  
  <pre><code>WITH RECURSIVE
  cnt(x) AS (
   SELECT 0
   UNION ALL
   SELECT x+1 FROM cnt
    LIMIT (SELECT ((julianday('2015-12-31') - julianday('2015-01-01')) + 1)))
  SELECT date(julianday('2015-01-01'), '+' || x || ' days') as date FROM cnt
  </code></pre>
  
  <p>p.s. If it will be in sqllite syntax-would be awesome!</p>