Maximum amount paid by Guest in SQL

Question:

Maximum amount paid by Guest

 Managements wants to know guest and maximum amount paid by each guest for any of the bookings. 

Write a query to display the Guest ID, Guest name and maximum amount paid by them(give alias name as MAX_AMOUNT). Sort the result based on guest ID. 

Maximum amount paid by Guest

Code:

Main.sql

select g.guestid, g.name, max(b.totalcharge) as MAX_AMOUNT
from guest g join booking b
           on b.guestid=g.guestid
           group by g.guestid, g.name
order by 1;

Recommended:

Leave a Comment

Your email address will not be published. Required fields are marked *