Task 3: The InstantRide Finance team wants to know the average discount amounts for each car in the InstantRide. Calculate the average discount amount as monetary value for the travels where a...


Task 3:


The InstantRide Finance team wants to know the average discount amounts for each car in the InstantRide. Calculate the average discount amount as monetary value for the travels where a discount is applied. You need to create a subquery over the TRAVELS table to retrieveCAR_ID andDISCOUNT_AMOUNT, calculated with2 decimals using the ROUND function.


To calculate the DISCOUNT_AMOUNT, multiply the TRAVEL_PRICE by the TRAVEL_DISCOUNT where the TRAVEL_DISCOUNT value is not NULL. Round the result to2 decimals.


Then you can use this subquery to get theCAR_ID andAVG of DISCOUNT_AMOUNT values, once again using the ROUND function on the average results. Group the results by the CAR_ID. UseCAR_ID andDISCOUNT_AMOUNT as column aliases and return it back to the Finance team.


Task: Calculate the average discount for each car.




You need to first calculate the discount amount for each car using the ROUND function. Then use a subquery to calculate average discount amount using AVG function.




CAR_ID<br>CAR PLATE<br>CAR_MODEL<br>CAR_YEAR<br>|1001<br>BB-542-AB<br>TOYOTA PRIUS<br>2018<br>1002<br>BB-883-EE<br>TESLA MODEL 3<br>2019<br>1003<br>BB-451-ZN<br>TOYOTA AURIS<br>2019<br>1004<br>BB-189-MM<br>MERCEDES E200<br>2019<br>

Extracted text: CAR_ID CAR PLATE CAR_MODEL CAR_YEAR |1001 BB-542-AB TOYOTA PRIUS 2018 1002 BB-883-EE TESLA MODEL 3 2019 1003 BB-451-ZN TOYOTA AURIS 2019 1004 BB-189-MM MERCEDES E200 2019
TRAVEL_ID<br>TRAVEL_START_TIME<br>TRAVEL_END_TIME<br>TRAVEL_START_LOCATION<br>TRAVEL_END_LOCATION<br>TRAVEL_PRICE<br>DRIVER_ID<br>CAR_ID<br>USER_ID<br>TRAVEL_DISCOUNT<br>5001<br>2019-10-01 04:04:55<br>2019-10-01 04:14:19<br>9614 York Road<br>84 Church Lane<br>15.44<br>2001<br>1003<br>3005<br>NULL<br>5002<br>2019-10-01 05:57:33<br>2019-10-01 06:12:33<br>47 Church Street<br>68 High Street<br>20.56<br>2001<br>1003<br>3006<br>NULL<br>5003<br>2019-10-01 13:35:20<br>2019-10-01 13:45:10<br>2 Windsor Road<br>95 West Street<br>12.32<br>2002<br>1001<br>3002<br>NULL<br>5004<br>2019-10-02 08:44:48<br>2019-10-02 09:15:28<br>9060 Mill Lane<br>27 Main Road<br>30.49<br>2003<br>1002<br>3001<br>0.13<br>5005<br>2019-10-02 16:38:54<br>2019-10-02 16:48:10<br>2 Queensway<br>24 Mill Lane<br>11.15<br>2001<br>1003<br>3007<br>NULL<br>5006<br>2019-10-03 19:12:14<br>2019-10-03 19:23:45<br>50 Main Road<br>93 Broadway<br>14.61<br>2003<br>1002<br>3007<br>0.10<br>5007<br>2019-10-03 16:06:36<br>2019-10-03 16:08:56<br>39 Park Road<br>91 West Street<br>4.41<br>2002<br>1004<br>3003<br>0.14<br>5008<br>2019-10-03 17:17:12<br>2019-10-03 17:37:42<br>37 The Drive<br>17 Stanley Road<br>25.12<br>2001<br>1003<br>3001<br>0.25<br>5009<br>2019-10-03 21:16:48<br>2019-10-03 21:26:18<br>77 Mill Road<br>724 Springfield Road<br>13.55<br>2001<br>1003<br>3005<br>NULL<br>5010<br>2019-10-03 23:21:40<br>2019-10-03 23:39:10<br>16 Church Road<br>30 North Road<br>25.62<br>2003<br>1002<br>3003<br>0.20<br>

Extracted text: TRAVEL_ID TRAVEL_START_TIME TRAVEL_END_TIME TRAVEL_START_LOCATION TRAVEL_END_LOCATION TRAVEL_PRICE DRIVER_ID CAR_ID USER_ID TRAVEL_DISCOUNT 5001 2019-10-01 04:04:55 2019-10-01 04:14:19 9614 York Road 84 Church Lane 15.44 2001 1003 3005 NULL 5002 2019-10-01 05:57:33 2019-10-01 06:12:33 47 Church Street 68 High Street 20.56 2001 1003 3006 NULL 5003 2019-10-01 13:35:20 2019-10-01 13:45:10 2 Windsor Road 95 West Street 12.32 2002 1001 3002 NULL 5004 2019-10-02 08:44:48 2019-10-02 09:15:28 9060 Mill Lane 27 Main Road 30.49 2003 1002 3001 0.13 5005 2019-10-02 16:38:54 2019-10-02 16:48:10 2 Queensway 24 Mill Lane 11.15 2001 1003 3007 NULL 5006 2019-10-03 19:12:14 2019-10-03 19:23:45 50 Main Road 93 Broadway 14.61 2003 1002 3007 0.10 5007 2019-10-03 16:06:36 2019-10-03 16:08:56 39 Park Road 91 West Street 4.41 2002 1004 3003 0.14 5008 2019-10-03 17:17:12 2019-10-03 17:37:42 37 The Drive 17 Stanley Road 25.12 2001 1003 3001 0.25 5009 2019-10-03 21:16:48 2019-10-03 21:26:18 77 Mill Road 724 Springfield Road 13.55 2001 1003 3005 NULL 5010 2019-10-03 23:21:40 2019-10-03 23:39:10 16 Church Road 30 North Road 25.62 2003 1002 3003 0.20
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here