I’m having trouble with my sqlite database. I’m trying to write an query that will generate a total bill for a specific guest (guestID)
GUEST
- GuestID (Primary Key, Type:Integer, Auto increment)
- FName (Type:Text)
- LName (Type:Text)
RESERVATION
- Reservation Number (Primary Key, Type: Integer, Auto increment)
- CheckIN (Type:DateTime)
- CheckOUT (Type:DateTime)
- GuestID (Type:Integer)
- RoomNumber (Type: Integer)
ROOM
- RoomNumber (Primary Key, type: Integer)
- RoomTypeID (type: Integer)
ROOMTYPE
- RoomTypeID (Primary Key, type: Integer)
- Bed (type: Text)
- Price (type: Integer)
I know that I would have to subtract Reservation.checkout from Reservation.checkin to get the number of days then multiply that by the RoomType.price so that would give me a total bill. So how would I write my sql query to give me a total bill for a specific guest (guestid)? I know you can join up to three tables but I don’t know how to join these four tables. Please help. Thank you in advance.
2 ways are 1 in the sql or 1 in the application level
1) sql:
You can modify to your needs basically the statement is to get the columns in guest table and compute the price he/she needs to pay by subtracting the check out and check in dates in seconds and multiply by the price down to per seconds.
2) app level:
You can probably run 2 sql statements to get the price of the particular room for particular guest.
Do the computation of price in your whatever language you are using php/ruby/java etc.