Question: Hello, I created a database in mysql workbench that includes the following tables and their attributes: hotel table, with attributes (hotelno, hotelname, city) room table,
Hello, I created a database in mysql workbench that includes the following tables and their attributes:
hotel table, with attributes (hotelno, hotelname, city)
room table, (roomno, hotelno,type, price)
guest table, (guestno, guestname, guestaddress, gender)
booking table, (hotelno, guestno, dateto, datefrom, roomno)
and now I want to calculate the total income of a particular hotel on a particular date.
for example, I have "marriott" hotel in 2 different cities, and I want to calculate the income of the at 2019-02-15.
I want to try it as a normal statement and as a function.
I tried this statement select sum(price) from room where hotelno=16522 and hotelno=16532; but I didn't know how to use the sum for a particular date.
and I tried this function:
Delimiter $$ create function getIncome(HName varchar(45),hotelNum int, IncomeDate date) returns double begin declare totalIncome varchar(45); select sum(price) into totalIncome from room where hotelNo=hotelNum and roomNo in (select roomNo from booking asb , hotel as h where deteFrom<=IncomeDate and dateTo>=IncomeDate and b.HotelNo = h.HotelNo and hotelName = HName); return totalIncome; end $$ Delimiter ;
but the problem was it will only calculate one room price while I have 2 bookings on the same date
**marriott number in the database is 16522 and 16532
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
