Extract the number of active customers in each city; the result should also contain cities with zero active customers in them

309 Views Asked by At

My query as follows along with screenshot from mysql workbench. I have used "Sum" instead of "Count" because, when I use "Count" then cities where active customers are actually "0" the results return as "1". Whereas when I use "Sum" then cities where active customers are actually "0" the results return as "0". Please advise if this is correct?

SELECT CT.CITY AS "City", SUM(CUST.ACTIVE) AS "No_of_active_customers" FROM CITY CT
INNER JOIN ADDRESS ADRS ON CT.CITY_ID = ADRS.CITY_ID
INNER JOIN CUSTOMER CUST ON ADRS.ADDRESS_ID = CUST.CUSTOMER_ID
GROUP BY CT.CITY
ORDER BY No_of_active_customers;

mysql_results

0

There are 0 best solutions below