title: SQL Least Earning Location Count
body: <p>I am using an online editor to solve query</p>
  
  <p><a href="https://www.jdoodle.com/execute-sql-online/" rel="nofollow noreferrer">https://www.jdoodle.com/execute-sql-online/</a></p>
  
  <p>have the following SQL Table</p>
  
  <pre><code>create table CITIES(id int, name String);
  create table USERS(id int, city_id String, name String, email);
  create table RIDES(id int, user_id int, distance int, fare int);
  
  INSERT INTO CITIES (id, name) VALUES
  (1,"Cooktown"),
  (2,"South Suzanne");
  
  INSERT INTO USERS (id, city_id, name, email) VALUES
  (1,2,"a","email"),
  (2,2,"b","email"),
  (3,1,"c","email"),
  (4,1,"d","email"),
  (5,1,"e","email"),
  (5,1,"f","email");
  
  INSERT INTO RIDES (id, user_id, distance, fare) VALUES
  (1,1,21,200),
  (2,3,6,55),
  (3,2,30,230),
  (4,2,16,125),
  (5,2,11,110),
  (6,6,30,285),
  (7,3,18,170),
  (8,1,6,50),
  (9,2,4,40),
  (10,1,10,90),
  (11,5,11,95),
  (12,5,16,140),
  (13,4,24,220),
  (14,6,17,160),
  (15,2,23,205),
  (16,2,11,90),
  (17,6,5,50),
  (18,3,19,180),
  (19,5,22,205),
  (20,4,6,60);
  </code></pre>
  
  <p><strong>Output should be :</strong></p>
  
  <p>South Suzanne 1050</p>
  
  <p>Cooktown 1710</p>
  
  <p>I tried following SQL Query but don't know how to count</p>
  
  <pre><code>select c.name, SUM(r.fare) from CITIES c
    left join USERS u on c.id=u.city_id 
    left join RIDES r on u.id=r.user_id
  </code></pre>
  
  <p><strong>Getting following output</strong></p>
  
  <p>Cooktown|2705</p>
  
  <p>Any help will be appreciated </p>