I have a query which i am unable to get the output.
Below is the query to be executed
Q: 2. Write a query to find the city Name, Id and Count that has got maximum number of vehicles associated.
Now, Given is the one table on which the query should be executed.
Vehicle_Detail_ID City_ID
56 242
57 242
58 242
59 243
60 241
61 242
62 245
Another table which has the city name
City_ID City_Name
242 Bangalore
243 ChamarajNager
241 Bellary
245 Chitradurga
EXPECTED OUTPUT:
City_ID No_Vehicles
242 4
Please tell me how to write the query which fetches me the right output.
Given below is the query which gives the city Id and its vehicle count.
TRIED:
SELECT c.city_id, COUNT(c.City_ID) AS NO_vehicles
FROM city c, vehicle_details v
WHERE c.City_ID = v.City_ID
GROUP BY c.City_ID
ACTUAL OUTPUT
City_ID No_Vehicles
242 4
243 1
241 1
245 1
Please help me to get max of these as shown in EXPECTED OUTPUT.
1 Answer