title: SQL Query Syntax
body: <p>Can anyone help me understand this line in <code>SQL</code>.</p>
  
  <pre><code>COALESCE
  (
  
      COUNT
      (
          DISTINCT (
                  CASE WHEN DATEDIFF(o.order_date,o.first_order_date) &lt;= 30 AND DATEDIFF(o.order_date,o.first_order_date) &gt; 0 AND DATE_FORMAT(o.first_order_date,'%Y-%m') &lt; DATE_FORMAT(now()- INTERVAL 1 MONTH,'%Y-%m') AND o.status_id in (11,22,24)
                      THEN o.customer_id
                  END
              )
      ),
      0   
  ) as '0-30 customer reorder'.
  </code></pre>