diff --git a/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md new file mode 100644 index 0000000000000..7434a2befc998 --- /dev/null +++ b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md @@ -0,0 +1,169 @@ +--- +comments: true +difficulty: 中等 +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README.md +tags: + - 数据库 +--- + + + +# [3601. Find Drivers with Improved Fuel Efficiency](https://leetcode.cn/problems/find-drivers-with-improved-fuel-efficiency) + +[English Version](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md) + +## 题目描述 + + + +

Table: drivers

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| driver_id   | int     |
+| driver_name | varchar |
++-------------+---------+
+driver_id is the unique identifier for this table.
+Each row contains information about a driver.
+
+ +

Table: trips

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| trip_id       | int     |
+| driver_id     | int     |
+| trip_date     | date    |
+| distance_km   | decimal |
+| fuel_consumed | decimal |
++---------------+---------+
+trip_id is the unique identifier for this table.
+Each row represents a trip made by a driver, including the distance traveled and fuel consumed for that trip.
+
+ +

Write a solution to find drivers whose fuel efficiency has improved by comparing their average fuel efficiency in the first half of the year with the second half of the year.

+ + + +

Return the result table ordered by efficiency improvement in descending order, then by driver name in ascending order.

+ +

The result format is in the following example.

+ +

 

+

Example:

+ +
+

Input:

+ +

drivers table:

+ +
++-----------+---------------+
+| driver_id | driver_name   |
++-----------+---------------+
+| 1         | Alice Johnson |
+| 2         | Bob Smith     |
+| 3         | Carol Davis   |
+| 4         | David Wilson  |
+| 5         | Emma Brown    |
++-----------+---------------+
+
+ +

trips table:

+ +
++---------+-----------+------------+-------------+---------------+
+| trip_id | driver_id | trip_date  | distance_km | fuel_consumed |
++---------+-----------+------------+-------------+---------------+
+| 1       | 1         | 2023-02-15 | 120.5       | 10.2          |
+| 2       | 1         | 2023-03-20 | 200.0       | 16.5          |
+| 3       | 1         | 2023-08-10 | 150.0       | 11.0          |
+| 4       | 1         | 2023-09-25 | 180.0       | 12.5          |
+| 5       | 2         | 2023-01-10 | 100.0       | 9.0           |
+| 6       | 2         | 2023-04-15 | 250.0       | 22.0          |
+| 7       | 2         | 2023-10-05 | 200.0       | 15.0          |
+| 8       | 3         | 2023-03-12 | 80.0        | 8.5           |
+| 9       | 3         | 2023-05-18 | 90.0        | 9.2           |
+| 10      | 4         | 2023-07-22 | 160.0       | 12.8          |
+| 11      | 4         | 2023-11-30 | 140.0       | 11.0          |
+| 12      | 5         | 2023-02-28 | 110.0       | 11.5          |
++---------+-----------+------------+-------------+---------------+
+
+ +

Output:

+ +
++-----------+---------------+------------------+-------------------+------------------------+
+| driver_id | driver_name   | first_half_avg   | second_half_avg   | efficiency_improvement |
++-----------+---------------+------------------+-------------------+------------------------+
+| 2         | Bob Smith     | 11.24            | 13.33             | 2.10                   |
+| 1         | Alice Johnson | 11.97            | 14.02             | 2.05                   |
++-----------+---------------+------------------+-------------------+------------------------+
+
+ +

Explanation:

+ + + +

The output table is ordered by efficiency improvement in descending order then by name in ascending order.

+
+ + + +## 解法 + + + +### 方法一 + + + +#### MySQL + +```sql + +``` + + + + + + diff --git a/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README_EN.md b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README_EN.md new file mode 100644 index 0000000000000..5fbccf0cd02c4 --- /dev/null +++ b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README_EN.md @@ -0,0 +1,169 @@ +--- +comments: true +difficulty: Medium +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md +tags: + - Database +--- + + + +# [3601. Find Drivers with Improved Fuel Efficiency](https://leetcode.com/problems/find-drivers-with-improved-fuel-efficiency) + +[中文文档](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README.md) + +## Description + + + +

Table: drivers

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| driver_id   | int     |
+| driver_name | varchar |
++-------------+---------+
+driver_id is the unique identifier for this table.
+Each row contains information about a driver.
+
+ +

Table: trips

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| trip_id       | int     |
+| driver_id     | int     |
+| trip_date     | date    |
+| distance_km   | decimal |
+| fuel_consumed | decimal |
++---------------+---------+
+trip_id is the unique identifier for this table.
+Each row represents a trip made by a driver, including the distance traveled and fuel consumed for that trip.
+
+ +

Write a solution to find drivers whose fuel efficiency has improved by comparing their average fuel efficiency in the first half of the year with the second half of the year.

+ + + +

Return the result table ordered by efficiency improvement in descending order, then by driver name in ascending order.

+ +

The result format is in the following example.

+ +

 

+

Example:

+ +
+

Input:

+ +

drivers table:

+ +
++-----------+---------------+
+| driver_id | driver_name   |
++-----------+---------------+
+| 1         | Alice Johnson |
+| 2         | Bob Smith     |
+| 3         | Carol Davis   |
+| 4         | David Wilson  |
+| 5         | Emma Brown    |
++-----------+---------------+
+
+ +

trips table:

+ +
++---------+-----------+------------+-------------+---------------+
+| trip_id | driver_id | trip_date  | distance_km | fuel_consumed |
++---------+-----------+------------+-------------+---------------+
+| 1       | 1         | 2023-02-15 | 120.5       | 10.2          |
+| 2       | 1         | 2023-03-20 | 200.0       | 16.5          |
+| 3       | 1         | 2023-08-10 | 150.0       | 11.0          |
+| 4       | 1         | 2023-09-25 | 180.0       | 12.5          |
+| 5       | 2         | 2023-01-10 | 100.0       | 9.0           |
+| 6       | 2         | 2023-04-15 | 250.0       | 22.0          |
+| 7       | 2         | 2023-10-05 | 200.0       | 15.0          |
+| 8       | 3         | 2023-03-12 | 80.0        | 8.5           |
+| 9       | 3         | 2023-05-18 | 90.0        | 9.2           |
+| 10      | 4         | 2023-07-22 | 160.0       | 12.8          |
+| 11      | 4         | 2023-11-30 | 140.0       | 11.0          |
+| 12      | 5         | 2023-02-28 | 110.0       | 11.5          |
++---------+-----------+------------+-------------+---------------+
+
+ +

Output:

+ +
++-----------+---------------+------------------+-------------------+------------------------+
+| driver_id | driver_name   | first_half_avg   | second_half_avg   | efficiency_improvement |
++-----------+---------------+------------------+-------------------+------------------------+
+| 2         | Bob Smith     | 11.24            | 13.33             | 2.10                   |
+| 1         | Alice Johnson | 11.97            | 14.02             | 2.05                   |
++-----------+---------------+------------------+-------------------+------------------------+
+
+ +

Explanation:

+ + + +

The output table is ordered by efficiency improvement in descending order then by name in ascending order.

+
+ + + +## Solutions + + + +### Solution 1 + + + +#### MySQL + +```sql + +``` + + + + + + diff --git a/solution/DATABASE_README.md b/solution/DATABASE_README.md index 0f42a179542bc..86044f6de4227 100644 --- a/solution/DATABASE_README.md +++ b/solution/DATABASE_README.md @@ -320,6 +320,7 @@ | 3570 | [查找无可用副本的书籍](/solution/3500-3599/3570.Find%20Books%20with%20No%20Available%20Copies/README.md) | `数据库` | 简单 | | | 3580 | [寻找持续进步的员工](/solution/3500-3599/3580.Find%20Consistently%20Improving%20Employees/README.md) | `数据库` | 中等 | | | 3586 | [寻找 COVID 康复患者](/solution/3500-3599/3586.Find%20COVID%20Recovery%20Patients/README.md) | `数据库` | 中等 | | +| 3601 | [Find Drivers with Improved Fuel Efficiency](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README.md) | | 中等 | | ## 版权 diff --git a/solution/DATABASE_README_EN.md b/solution/DATABASE_README_EN.md index 77d329ceb1c68..667bb07e9856c 100644 --- a/solution/DATABASE_README_EN.md +++ b/solution/DATABASE_README_EN.md @@ -318,6 +318,7 @@ Press Control + F(or Command + F on | 3570 | [Find Books with No Available Copies](/solution/3500-3599/3570.Find%20Books%20with%20No%20Available%20Copies/README_EN.md) | `Database` | Easy | | | 3580 | [Find Consistently Improving Employees](/solution/3500-3599/3580.Find%20Consistently%20Improving%20Employees/README_EN.md) | `Database` | Medium | | | 3586 | [Find COVID Recovery Patients](/solution/3500-3599/3586.Find%20COVID%20Recovery%20Patients/README_EN.md) | `Database` | Medium | | +| 3601 | [Find Drivers with Improved Fuel Efficiency](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md) | | Medium | | ## Copyright diff --git a/solution/README.md b/solution/README.md index f2b17e9c5826d..5342697e0355c 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3611,6 +3611,7 @@ | 3598 | [相邻字符串之间的最长公共前缀](/solution/3500-3599/3598.Longest%20Common%20Prefix%20Between%20Adjacent%20Strings%20After%20Removals/README.md) | | 中等 | 第 456 场周赛 | | 3599 | [划分数组得到最小 XOR](/solution/3500-3599/3599.Partition%20Array%20to%20Minimize%20XOR/README.md) | | 中等 | 第 456 场周赛 | | 3600 | [升级后最大生成树稳定性](/solution/3600-3699/3600.Maximize%20Spanning%20Tree%20Stability%20with%20Upgrades/README.md) | | 困难 | 第 456 场周赛 | +| 3601 | [Find Drivers with Improved Fuel Efficiency](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README.md) | | 中等 | | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 2396b5fc57bee..b583e42d3f207 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -3609,6 +3609,7 @@ Press Control + F(or Command + F on | 3598 | [Longest Common Prefix Between Adjacent Strings After Removals](/solution/3500-3599/3598.Longest%20Common%20Prefix%20Between%20Adjacent%20Strings%20After%20Removals/README_EN.md) | | Medium | Weekly Contest 456 | | 3599 | [Partition Array to Minimize XOR](/solution/3500-3599/3599.Partition%20Array%20to%20Minimize%20XOR/README_EN.md) | | Medium | Weekly Contest 456 | | 3600 | [Maximize Spanning Tree Stability with Upgrades](/solution/3600-3699/3600.Maximize%20Spanning%20Tree%20Stability%20with%20Upgrades/README_EN.md) | | Hard | Weekly Contest 456 | +| 3601 | [Find Drivers with Improved Fuel Efficiency](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md) | | Medium | | ## Copyright