-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL17_BusinessRide.sql
More file actions
23 lines (19 loc) · 1.43 KB
/
Copy pathSQL17_BusinessRide.sql
File metadata and controls
23 lines (19 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*You’re given a table of Uber rides that contains the mileage and the purpose for the business expense.
You’re asked to find business purposes that generate the most miles driven for passengers that use Uber for their
business transportation. Find the top 3 business purpose categories by total mileage*/
CREATE TABLE my_uber_drives (start_date DATETIME,end_date DATETIME,category VARCHAR(50),start VARCHAR(50),stop VARCHAR(50),
miles FLOAT,purpose VARCHAR(50));
INSERT INTO my_uber_drives (start_date, end_date, category, start, stop, miles, purpose)
VALUES('2016-01-01 21:11', '2016-01-01 21:17', 'Business', 'Fort Pierce', 'Fort Pierce', 5.1, 'Meal/Entertain'),
('2016-01-02 01:25', '2016-01-02 01:37', 'Business', 'Fort Pierce', 'Fort Pierce', 5, NULL),
('2016-01-02 20:25', '2016-01-02 20:38', 'Business', 'Fort Pierce', 'Fort Pierce', 4.8, 'Errand/Supplies'),
('2016-01-05 17:31', '2016-01-05 17:45', 'Business', 'Fort Pierce', 'Fort Pierce', 4.7, 'Meeting'),
('2016-01-06 14:42', '2016-01-06 15:49', 'Business', 'Fort Pierce', 'West Palm Beach', 63.7, 'Customer Visit'),
('2016-01-06 17:15', '2016-01-06 17:19', 'Business', 'West Palm Beach', 'West Palm Beach', 4.3, 'Meal/Entertain'),
('2016-01-06 17:30', '2016-01-06 17:35', 'Business', 'West Palm Beach', 'Palm Beach', 7.1, 'Meeting');
Select purpose,sum(miles) as total_miles
from my_uber_drives
where category='Business'
group by purpose
order by total_miles desc
Limit 3;