Skip to content
Advertisement

i need to display customer’s first name and last name who have made the most number of booking. Using select

So using this table i have to display customers F Name and L name, so I tried using (Group By) but didn’t work

>     CREATE TABLE bookingxx (`enter code here`   BookingLastname varchar(20) DEFAULT NULL,   BookingFirstname varchar(20) DEFAULT NULL,
> BookingNumber varchar(10) DEFAULT NULL,   BookingState varchar(20)
> DEFAULT NULL,   BookingDate date DEFAULT NULL,   FlightNumber
> varchar(15) DEFAULT NULL,   SeatsBooked int DEFAULT NULL,  
> TotalCharges int DEFAULT NULL,   BookingTotal int DEFAULT NULL );
> 
> 
> INSERT INTO bookingxx (BookingFirstname,BookingLastname,BookingNumber,
> BookingState, BookingDate, FlightNumber, SeatsBooked, TotalCharges,
> BookingTotal) VALUES ('James','Bond','BK01', 'Perak', '2021-06-12',
> 'FLT6', 200, 6000000, 200), ('John','Weak','BK02', 'Negeri Sembilan',
> '2021-06-16', 'FLT7', 140, 1400000, 140), ('John','Tina','BK03',
> 'Pahang', '2021-06-15', 'FLT3', 300, 8000000, 300),
> ('Uno','Tabalo','BK04', 'Sabah', '2021-06-13', 'FLT6', 100, 1000000,
> 100), ('Zratus','Kratus','BK05', 'Sarawak', '2021-06-01', 'FLT5', 240,
> 4400000, 240), ('Mohd','Ali','BK06', 'Perak', '2021-06-10', 'FLT6',
> 330, 3800000, 330), ('Hussam','Saleh','BK07', 'Wilayah Persekutuan ',
> '2021-06-17', 'FLT8', 190, 1900000, 190), ('Hamza','Hazem','BK08',
> 'Pahang', '2021-06-03', 'FLT3', 80, 800000, 80), ('Ali','Anas','BK09',
> 'Sarawak', '2021-06-01', 'FLT5', 90, 100000, 90),
> ('Abdull','Jabar','BK10', 'Negeri Sembilan', '2021-06-02', 'FLT7',
> 300, 5000000, 400);

Advertisement

Answer

It sounds like you just need the name of the person with the highest value Bookingtotal.

You don’t specify your RDBMS, however

select top(1) BookingLastName, BookingFirstName
from bookingxx
order by BookingTotal desc

Your specific database might use limit instead of top; you can also use with ties for where the same total is shared by more than one.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement