title: Is it possible to group twice without subqueries?
body: <p>I answered one of the questions on SO with the following query:</p>
  
  <pre><code>SELECT s.address
  FROM shop s 
  JOIN visit v ON s.shopid = v.shopid 
  JOIN customer c ON v.customerid = c.customerid 
  WHERE c.cname = 'John' 
  GROUP BY 
  s.address
  , c.customerid 
  HAVING COUNT(*) &gt; 1
  </code></pre>
  
  <p>This works fine, but will return duplicate addresses if there are 2 or more John's for a given shop who meet the query's criteria, so I modified my answer:</p>
  
  <pre><code>SELECT DISTINCT a.address 
  FROM 
  (
  SELECT s.address
  FROM shop s 
  JOIN visit v ON s.shopid = v.shopid 
  JOIN customer c ON v.customerid = c.customerid 
  WHERE c.cname = 'John' 
  GROUP BY 
  s.address
  , c.customerid 
  HAVING COUNT(*) &gt; 1
  ) a
  </code></pre>
  
  <p>Now my question is: is it possible to achieve grouping first when evaluating the aggregate expression and then before selecting in a single query?</p>