



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




DATABASE: GuestHouse Database
Table: guest
Table: Occupied_room
Table: reservation
Table: room
Aggregate functions:
1)Select total number of room in GuestHouse
Query: select DISTINCT count(r_id) from room
2)Count the number of guest having nationality Indian
Query: select count(guest_id) as Nation from guest where nationality=’indian’
3)Find average of cost where status is available
Query :select avg(cost) from room where STATUS='available
4)How many different guests have made reservation for march?
SELECT COUNT(DISTINCT guest_id) FROM reservation
WHERE (date_in <= DATE "2017-03-01" AND date_out >= DATE "2017-03-09") OR
(date_in >= DATE "2017-03-01" AND date_in <= DATE "2017-03-31");
5)select count where check out date of guest is ‘2017-03-15’
Query :Select count(*) AS total_checking_out from reservation where date_out=2017-03-
6)Retrieve data of room having minimum price
Query :Select min(cost) from room
7)Retrieve guest name and room having max cost
Query :select fname,lname,max(cost),r_id from guest,room WHERE guest.r_id=room.r_id
8)What is the total revenue from all double rooms?
Query : select sum(cost) from room where room_type_id='2'
3)select reservations where the guest id is from 10 to 15
4)Select guest having reservation done by ‘Dang’.
Query: SELECT fname,guest_id FROM guest WHERE guest_id IN (SELECT guest_id FROM reservation WHERE made_by = 'dang')
Query: select r_id from room where cost = 1000 and r_id in
(select r_id from guest where fname IN (select fname from guest where address='pune'))
Query: select * from guest where guest_id =(select guest_id from reservation where made_by=’sandy’)
Joins:
1)Query: SELECT guest.guest_id, guest.fname, reservation.made_by FROM reservation INNER JOIN guest ON reservation.guest_id = guest.guest_id
3)List all the guest with reservation made by with address as ponda.
Query: select guest.fname,guest.lname,guest.address,reservation.guest_id,reservation.made_by from guest JOIN reservation ON guest.guest_id=reservation.guest_id where address='ponda'