Computer Science, asked by margajsiddhi6486, 5 hours ago

A ride hailing company has their DB structured in 3 major tables as described in SCHEMA belowWrite a query to fetch the city names along with Earnings from each city .Earning are calculated as the sum of fare of all the rides taken that city. The output should be structured as: cities.name earnings. The output is sorted ascending by earnings,then ascending by the city name.​

Answers

Answered by kargwalm93
8

Answer:

sorry for answer sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry sorry y

Answered by surajnegi0600
0

Answer:

Here's a sample SQL query to fetch the city names along with earnings from each city:

SELECT cities.name, SUM(rides.fare) AS earnings

FROM cities

JOIN drivers ON cities.id = drivers.city_id

JOIN rides ON drivers.id = rides.driver_id

GROUP BY cities.name

ORDER BY earnings ASC, cities.name ASC;

Explanation:

This query performs a 'JOIN' between the 'cities' and 'drivers' tables on the 'city_id' column and between the 'drivers' and 'rides' tables on the 'driver_id' column. Then, it calculates the sum of fares for each city using the 'SUM' function and 'GROUP BY' clause. The result is ordered by earnings in ascending order, then by city name in ascending order using the 'ORDER BY' clause.

More questions and answers:

https://brainly.in/question/34286132?referrer=searchResults

https://brainly.in/question/39054442?referrer=searchResults

#SPJ3

Similar questions