title: Percentage Increase/Decrease in SUM between 2 dates where first SUM is zero
body: <p>I have a mysql query like this -</p>
  
  <pre><code>SELECT location, 
  SUM(IF(action_dt_tm BETWEEN '2013-01-01' AND '2013-06-30',1,0)) AS previous, 
  SUM(IF(action_dt_tm BETWEEN '2013-07-01' AND '2013-12-31',1,0)) AS current, 
  SUM(IF(action_dt_tm BETWEEN '2013-07-01' AND '2013-12-31',1,0))- 
  SUM(IF(action_dt_tm BETWEEN '2013-01-01' AND '2013-06-30',1,0)) as diff, ( 
  SUM(IF(action_dt_tm BETWEEN '2013-07-01' AND '2013-12-31',1,0))- 
  SUM(IF(action_dt_tm BETWEEN '2013-01-01' AND '2013-06-30',1,0)))/ 
  SUM(IF(action_dt_tm BETWEEN '2013-01-01' AND '2013-06-30',1,0))*100 AS percent 
  FROM table group by location order by percent DESC
  </code></pre>
  
  <p>which I based on previous answers found on stackoverflow.</p>
  
  <p>The idea is to return a location, a previous date range count, a current count (these ranges change), the numeric difference between previous and current and the % increase or decrease.</p>
  
  <p>Something like -</p>
  
  <pre><code>LOCATION 1     38    27    -11    -28.94%
  LOCATION 2     6     18     12    200.00%
  </code></pre>
  
  <p>etc</p>
  
  <p>The code above, while probably clunky, seems to work, EXCEPT when the PREVIOUS count is found to be zero, then percent is returned as NULL, instead of the increase/decrease.</p>
  
  <p>ie</p>
  
  <pre><code>LOCATION 3     0     32      32     (NULL)
  </code></pre>
  
  <p>Can anyone advise how to alter the query to resolve this please.</p>