title: MySQL DATE_ADD usage, 5 day interval
body: <p>I'm trying to select the order total sum ($) and invoice count over a 5 day period in a single query.  I can't seem to get this to happen though.  The current query I have is here...</p>
  
  <pre><code>SELECT
      COUNT(id) as invoice_count,
      SUM(orderTotal) as orders_sum,
      UNIX_TIMESTAMP(created) as created
  FROM ids_invoice
  WHERE DATE_ADD(created, INTERVAL +1 DAY)
  AND userId = 23 LIMIT 5'
  </code></pre>
  
  <p>I'm not entirely sure DATE_ADD is the right function I'm looking for.</p>
  
  <p>Currently I'm getting....</p>
  
  <pre><code>Array ( 
      [0] =&gt; Array ( 
          [invoice_count] =&gt; 420
          [orders_total] =&gt; 97902.90
          [created] =&gt; 1252596560
      )
  )
  
  Array ( 
      [0] =&gt; Array ( 
          [invoice_count] =&gt; 68
          [orders_total] =&gt; 14193.20
          [created] =&gt; 1262900809
      )
  )
  </code></pre>
  
  <p>I'd like to get something more like...</p>
  
  <pre><code>Array ( 
      [0] =&gt; Array ( 
          [invoice_count] =&gt; 18
          [orders_total] =&gt; 4902.90
          [date] =&gt; 04-19-2010
      )
  )
  
  Array ( 
      [0] =&gt; Array ( 
          [invoice_count] =&gt; 12
          [orders_total] =&gt; 5193.20
          [date] =&gt; 04-20-2010
      )
  )
  </code></pre>
  
  <p>I'm fairly new to mysql date functions so perhaps I just missed the function I needed when going through mysql docs.</p>
  
  <p><strong>UPDATE</strong>
  I've updated my query... This still does not pull a row for each day that there were invoices for.  It's only pulling invoices from the 19th when there are invoices from the 20th that meet the userId criteria.</p>
  
  <pre><code>SELECT
      COUNT(id) as invoice_count,
      SUM(orderTotal) as orders_sum,
      UNIX_TIMESTAMP(created) as created
  FROM ids_invoice
  WHERE
      created BETWEEN "2010-04-19 00:00:00" AND DATE_ADD("2010-04-19 00:00:00", INTERVAL +5 DAY) AND
      userId = 17
  </code></pre>