← 返回 doordash 的题目列表SQL: Restaurant query (classic)
类型:online_judge
SQL Coding: Restaurant query (classic)
Assume you have tables like:
restaurants(restaurant_id, name, city, ...)
orders(order_id, restaurant_id, user_id, order_time, ...)
Write a runnable SQL query to solve one common “restaurant” analytics task (pick the version you know best):
Find the restaurant(s) with the most orders per city (output: city, restaurant_id, name, order_cnt), including ties.
Only count orders in the last 30 days.
Requirements:
Explain why DISTINCT is needed or not needed.
Explain how adding an OR condition in the WHERE clause can change duplication and how DISTINCT impacts the result (e.g., duplicate rows vs. duplicate counts).