Docsity

executed dbms queries, Exercises of Database Management Systems (DBMS)

Toggle sidebar
bg1
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
pf3
pf4
pf5

Partial preview of the text

Download executed dbms queries and more Exercises Database Management Systems (DBMS) in PDF only on Docsity!

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'

  1. List all the room which are not reserved and also not occupied

Query:select * from room where status='available' and r_id not IN(select r_id

from occupied_room o inner JOIN reservation r on

o.reservation_id=r.reservation_id where date_in >='2017-3-10' and date_out <=

3)select reservations where the guest id is from 10 to 15

Query: SELECT reservation_id FROM reservation WHERE guest_id

BETWEEN 10 AND 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'))

  1. List down reservation made by sandy. ('=' because just one row present in database which it returns).

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

  1. Query: SELECT occupied_room.check_in, room.r_number, room.status FROM occupied_room RIGHT JOIN room ON room.r_id= occupied_room.r_id ORDER BY room.r_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'