Guest details and Total Charges paid in SQL

Guest details and Total Charges paid

Display guest details who paid total charges RS.50000 and above. Write a query to fetch Guest id, Guest name and Sum of total charges. Give alias name to total charges as  TOTALPAID. Sort the result by guest id.

Guest details and Total Charges paid
Guest details and Total Charges paid

SQL Code: Guest details and Total Charges paid Solution

select guest.guestid, guest.name, sum(booking.totalcharge) as
TOTALPAID from guest
join booking on booking.guestid=guest.guestid
group by guest.guestid,guest.name
having sum(booking.totalcharge)>=50000
order by guest.guestid;

Related:

Leave a Comment

twenty − 15 =