Task 4: The InstantRide Driver Relationship team wants to create groups for drivers according to their ratings such as 3+ or 4+. For instance, a driver with the rating 3.8 will be 3+; whereas a driver with the rating 4.2 will be 4+. You need to return a two column output with DRIVER_ID and DRIVER_RATING which has first FLOOR applied and then CONCAT with + sign for all drivers with a rating greater than 0.
Create groups of drivers according to their ratings.
MySQL programming language
Follow the below mysql code which return driver_id and driver_rating as mention in problem statement. I have inserted some dummy data.
/*create table driver_info */
create table Driver_Info(Driver_Id integer, rating double);
/* insert some data in table*/
insert into Driver_Info(Driver_Id, rating) values(1, 23.45);
insert into Driver_Info(Driver_Id, rating) values(2, 3.4);
insert into Driver_Info(Driver_Id, rating) values(3, 4);
insert into Driver_Info(Driver_Id, rating) values(5, 0);
insert into Driver_Info(Driver_Id, rating) values(7, -5);
/* select query to print id and rating */
select Driver_Id,concat(cast(substring_index(rating, '.', 1) as unsigned),'+') as Driver_Rating from Driver_Info where rating > 0;
Output:-
Get Answers For Free
Most questions answered within 1 hours.