title: insert a where condition in an aggregated sql statement
body: <p>I've been trying to put a "where" clause in my aggregated sql statement,</p>
  
  <p>what I want is to get the sum of qty and only display those who have a 30 or less (including zero) quantities sold.
  I tried putting it in the "on" part but to no avail</p>
  
  <pre><code>SELECT p.id, p.names,p.image, coalesce(sum(o.qty), 0) as sum_product_qty 
  from products p left join orders_item o on p.id = o.product_id                        
  and date(o.datesales) &lt;= curdate() and date(o.datesales) &gt;= curdate() - interval 6 day  and
  sum_product_qty &lt;= 30 group by p.id, p.names order by sum_product_qty desc
  </code></pre>
  
  <p>this is my sql statement</p>
  
  <pre><code>SELECT p.id, p.names,p.image, coalesce(sum(o.qty), 0) as sum_product_qty 
  from products p left join orders_item o on p.id = o.product_id 
  and date(o.datesales) &lt;= curdate() and date(o.datesales) &gt;= curdate() - interval 6 day
  group by p.id, p.names order by sum_product_qty desc
  </code></pre>