title: Issue with counting in MySQL
body: <p>I try to solve an issue but I need help :)</p>
  
  <p>Actually this query works, I have the sum of all sales in the last colums:</p>
  
  <pre><code>SELECT DISTINCT epps.SKU, epc.name , 
                   COUNT(*) FROM ERP_CUSTOMER_ORDER eco
                  INNER JOIN ERP_CUSTOMER_ORDER_ITEMS_2 ecoi2 ON ecoi2.ERP_CUSTOMER_ORDER_index = eco.`index`
                  INNER JOIN ERP_PROD_PRODUCT_SIZES epps ON ecoi2.prod_index = epps.ID
                  INNER JOIN ERP_PROD_CATALOG epc ON epps.`SKUf ID`= epc.`index`
  
                          WHERE (eco.state = "processing" OR eco.state= "complete")
                              AND eco.created_at &gt; DATE_ADD("2015-11-06",INTERVAL 12 HOUR)
                              AND eco.created_at &lt; DATE_ADD("2015-12-06",INTERVAL 12 HOUR)
                              AND epc.attribute_set = "Contact Lenses"
                              AND eco.order_location = "KL"
  
  GROUP BY epps.SKU
  ORDER BY COUNT(*) DESC
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/GNyYJ.jpg" alt="Result of this query"></p>
  
  <p>I want the number of products sold per 30 days period. I also would like the number of products sold the last month. Yet it doesn't work. This is my new query:</p>
  
  <p>I would like to compare the sales between 2 different months</p>
  
  <pre><code>SELECT DISTINCT epps.SKU, epc.name , 
                  (SELECT COUNT(*) FROM ERP_CUSTOMER_ORDER eco
                  INNER JOIN ERP_CUSTOMER_ORDER_ITEMS_2 ecoi2 ON ecoi2.ERP_CUSTOMER_ORDER_index = eco.`index`
                  INNER JOIN ERP_PROD_PRODUCT_SIZES epps ON ecoi2.prod_index = epps.ID
                  INNER JOIN ERP_PROD_CATALOG epc ON epps.`SKUf ID`= epc.`index`
  
                          WHERE (eco.state = "processing" OR eco.state= "complete")
                              AND eco.created_at &gt; DATE_ADD("2015-11-06",INTERVAL 12 HOUR)
                              AND eco.created_at &lt; DATE_ADD("2015-12-06",INTERVAL 12 HOUR)
                              AND epc.attribute_set = "Contact Lenses"
                              AND eco.order_location = "KL"
                              ),
  
  
                              (SELECT COUNT(*) FROM ERP_CUSTOMER_ORDER eco
                  INNER JOIN ERP_CUSTOMER_ORDER_ITEMS_2 ecoi2 ON ecoi2.ERP_CUSTOMER_ORDER_index = eco.`index`
                  INNER JOIN ERP_PROD_PRODUCT_SIZES epps ON ecoi2.prod_index = epps.ID
                  INNER JOIN ERP_PROD_CATALOG epc ON epps.`SKUf ID`= epc.`index`
  
                          WHERE (eco.state = "processing" OR eco.state= "complete")
                              AND eco.created_at &gt; DATE_ADD("2015-10-06",INTERVAL 12 HOUR)
                              AND eco.created_at &lt; DATE_ADD("2015-11-06",INTERVAL 12 HOUR)
                              AND epc.attribute_set = "Contact Lenses"
                              AND eco.order_location = "KL"
                              )
  FROM ERP_CUSTOMER_ORDER eco
                  INNER JOIN ERP_CUSTOMER_ORDER_ITEMS_2 ecoi2 ON ecoi2.ERP_CUSTOMER_ORDER_index = eco.`index`
                  INNER JOIN ERP_PROD_PRODUCT_SIZES epps ON ecoi2.prod_index = epps.ID
                  INNER JOIN ERP_PROD_CATALOG epc ON epps.`SKUf ID`= epc.`index`                                          
  GROUP BY epps.SKU 
  ORDER BY COUNT(*) DESC
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/OcmSa.jpg" alt="Result of this query"></p>
  
  <p>I used roughly the same framework but I can't have the same result than before.</p>
  
  <p>Thanks a lot!
  Guillaume</p>