title: GROUP BY Function Counting Total Matches For Each Row | SQL/Oracle
body: I'm trying to query a couple of my tables to show the number (count) of premium members at <b> each branch </b>of a pet store chain (there are standard and premium members at each) and the address of each store (the address is a structured type consisting of street + number, city and postcode/zipcode.
  <p>When trying to create the query, it keeps counting the total number of premium membership customers across all branches and showing that as the count for each store/branch.</p>
  <p>As shown below, the Los Angeles, San Francisco and San Diego branches all show a count of 9 for the number of premium customers, which is the total number premium membership customers across all branches. The correct count should be 5 for LA, 3 for SF, and 1 for SD.</p>
  <p>I'm not sure what is wrong with my code?</p>
  <pre>
  
  SELECT COUNT(x.customerID), y.storeAddress.streetAddress, y.storeAddress.city, y.storeAddress.postcode
  FROM petStoreMemberships x, petStoreBranches y
  WHERE x.membership = 'Premium'
  GROUP BY y.storeaddress.streetAddress, y.storeaddress.city, y.storeaddress.postcode
  ORDER BY COUNT(x.customerID);
  
  </pre>
  
  <p><a href="https://i.stack.imgur.com/m8F22.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m8F22.png" alt="Query Result" /></a></p>