1651.(Hard)Hopper Company Queries III
Table: Drivers
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| driver_id | int |
| join_date | date |
+-------------+---------+
driver_id is the primary key for this table.
Each row of this table contains the driver's ID and the date they joined the Hopper company.Table: Rides
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| ride_id | int |
| user_id | int |
| requested_at | date |
+--------------+---------+
ride_id is the primary key for this table.
Each row of this table contains the ID of a ride, the user's ID that requested it, and the day they requested it.
There may be some ride requests in this table that were not accepted.Table: AcceptedRides
Write an SQL query to compute the average_ride_distance and average_ride_duration of every 3-month window starting from January - March 2020 to October - December 2020. Round average_ride_distance and average_ride_duration to the nearest two decimal places.
The average_ride_distance is calculated by summing up the total ride_distance values from the three months and dividing it by 3. The average_ride_duration is calculated in a similar way.
Return the result table ordered by month in ascending order, where month is the starting month's number (January is 1, February is 2, etc.).
The query result format is in the following example.
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/hopper-company-queries-iii
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
Solution
和 1635.(Hard)Hopper 公司查询 I 题基本一样。
不需要
Drivers表。window=k滑动窗口函数over(order by xxx ROWS BETWEEN current row and k-1 following)ROWS BETWEEN current row and k-1/UNBOUNDED following当前行向后k行ROWS BETWEEN k-1/UNBOUNDED preceding and current row当前行向前k行 UNBOUNDED是指flexible window
Last updated
Was this helpful?