LeetCode(数据库)- Hopper Company Queries III

简介: LeetCode(数据库)- Hopper Company Queries III

题目链接:点击打开链接

题目大意:计算连续每个季度的平均指标(ride_distance、ride_duration)。

解题思路:略。

AC 代码


WITH RECURSIVE cal AS(
    SELECT 1 l, 1 mon1, 2 mon2, 3 mon3
    UNION ALL
    SELECT l + 1, mon1 + 1, mon1 + 2, mon1 + 3 FROM cal WHERE mon1 < 10
),
t AS(SELECT a.ride_id, ride_distance, ride_duration, requested_at FROM Rides r JOIN AcceptedRides a ON r.ride_id = a.ride_id AND requested_at BETWEEN '2020-01-01' AND '2020-12-31')
SELECT l month, IFNULL(ROUND(SUM(ride_distance) / 3, 2), 0) average_ride_distance, IFNULL(ROUND(SUM(ride_duration) / 3, 2), 0) average_ride_duration
FROM cal LEFT JOIN t ON MONTH(requested_at) IN (mon1, mon2, mon3)
GROUP BY l  
目录
相关文章
|
数据库
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
|
SQL 数据库
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
|
SQL 数据库
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
|
数据库
LeetCode(数据库)- Hopper Company Queries II
LeetCode(数据库)- Hopper Company Queries II
100 0
LeetCode(数据库)- Hopper Company Queries II
|
数据库
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
203 0
|
数据库
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
118 0
|
数据库
LeetCode(数据库)- Number of Accounts That Did Not Stream
LeetCode(数据库)- Number of Accounts That Did Not Stream
117 0
|
数据库
LeetCode(数据库)- The Airport With the Most Traffic
LeetCode(数据库)- The Airport With the Most Traffic
136 0
|
数据库
LeetCode(数据库)- The Category of Each Member in the Store
LeetCode(数据库)- The Category of Each Member in the Store
121 0
|
数据库
LeetCode(数据库)- 上级经理已离职的公司员工
LeetCode(数据库)- 上级经理已离职的公司员工
134 0