title: HAVING COUNT(DISTINCT `goodfor_what`.`name`) = 3 cause error message
body: <p>I got error message </p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near GROUP BY name HAVING COUNT(DISTINCT goodfor_when.name) = 1 .</p>
  </blockquote>
  
  <p>Here is part of the query where error happen</p>
  
  <pre><code>                    ....
          WHERE 
          ( `city`.`name` = "London" ) AND 
          `goodfor_what`.`name` IN ("Beers","Wine","Food") 
          GROUP BY name 
  
          HAVING COUNT(DISTINCT `goodfor_what`.`name`) = 3 AND `goodfor_when`.`name` IN ('Daytime') GROUP BY name
          HAVING COUNT(DISTINCT `goodfor_when`.`name`) = 1 ORDER BY `t`.`name`, `t`.`id`;
  </code></pre>
  
  <p>But works if remove line</p>
  
  <pre><code>HAVING COUNT(DISTINCT `goodfor_what`.`name`) = 3 AND `goodfor_when`.`name` IN ('Daytime') GROUP BY name
  </code></pre>