Sei sulla pagina 1di 4

1. List all double or family rooms with a price below £40.

00 per night, in
ascending order of price.
SELECT *
FROM Room
WHERE type IN (‘double’,’family’) AND price< 40,00
ORDER BY price;

2. List the bookings for which no dateTo has been specified.


SELECT*
FROM Booking
WHERE dateTo IS NULL;

3. What is the average price of a room?


SELECT AVG(price) AS Average Price
FROM Room;

4. What is the total revenue per night from all double rooms?
SELECT SUM(price) AS total revenue
FROM Room
WHERE type=’Double’;

5. List the details of all rooms at the Grosvenor Hotel, including the name of the
guest staying in the room, if the room is occupied.
SELECT r.*
FROM Room r
LEFT JOIN (SELECT g.guestNo, h.hotelNo, b.roomNo
FROM Guest g, Hotel h, Booking b
WHERE g.guestNo=b.guestNo AND b.hotelNo=h.hotelNo
AND hotelname=’Grosvenor’ AND dateTO>=CURDATE())
AS TODAY ON r.hotelNo=TODAY.hotelNo AND
r.roomNo=TODAY.roomNo;

6. What is the total income from bookings for the Grosvenor Hotel today?
SELECT SUM(price)
FROM Room r, Booking b, Hotel h
WHERE r.roomNo=b.roomNo AND
r.hotelNo=b.hotelNo AND
r.hotelNo=h.hotelNo AND
b.dateto>=CURDATE() AND
h.hotelname=’Grosvenor’;
7. What is the average number of bookings for each hotel in August?
SELECT hotelname, AVG(BookCount) AS AvgBookCount
FROM (SELECT hotelname, COUNT(hotelno) AS BookCount
FROM Hotel h, Booking b
WHERE h.hotelno=b.hotelno AND
b.datefrom BETWEEN ‘1/08/19’ AND ‘31/08/19’
GROUP BY hotelname)
GROUP BY hotelname;

8. What is the most commonly booked room type for each hotel in London?
SELECT hotelname, type, MAX(BookCount)
FROM (SELECT hotelname,type, COUNT(type) AS BookCOunt)
FROM Hotel h, Room r
WHERE h.hotelNo=r.hotelNo AND city=’London’
GROUP BY hotelname, type)
GROUP BY hotelname, type
ORDER BY hotelname, type;

SOAL 2
1. Tampilkan id dari pada staff berikut gaji perbulannya, dengan syarat, gaji
perbulan staff tersebut lebih besar dari 1000 pound. Kemudian urutkan
berdasarkan gaji yang terbesar.
SELECT StaffNo As Id, (Salary/12) As GajiPerbulan
FROM Staff
WHERE Salary/12 >1000
ORDER BY Salary DESC;

2. Tampilkan ID property yang memiliki kamar lebih atau sama dengan 4 tetapi
biaya sewanya lebih kecil dari 500 pound.
SELECT propertyNo As ID
FROM PropertyForRent
WHERE rooms >= 4 AND rent < 500;

3. Tampilkan info lengkap private owner yang beralamat di Glasgow tetapi first
namenya tidak berawalan “T”.
SELECT *
FROM PrivateOwner
WHERE address LIKE ‘%Glasgow%’ AND fName NOT LIKE
‘T%’;

4. Tampilkan first name dan last name dari semua staff yang berada pada
branch B005 atau B007.
SELECT fName, lName
FROM Staff
WHERE branchNo IN (‘B005’,’B007’);

5. Tampilkan kode properti dan kodeposnya, dimana pada awal kodepos tsb
terdapat string “G12”.
SELECT propertyNo AS Kode property,postcode
FROM PropertyForRent
WHERE Postcode LIKE ‘G12%’;

6. Untuk setiap tipe properti tampilkan type, jumlah properti, total biaya sewa
dan total jumlah kamar properti tersebut. Urutkan hasilnya berdasarkan tipe
properti.
SELECT type, COUNT(propertyNo) AS Jumlah Properti,
COUNT(rent)As Total biaya Sewa, COUNT(room) As Total
Jumlah kamar
FROM PropertyForRent
GROUP BY type
ORDER BY type;

7. Tampilkan id dari properti owner beserta total jumlah properti yang


dimilikinya dan total jumlah kamar dari properti-properti tersebut, dengan
syarat jumlah properti yang dimiliki tersebut minimum 2 properti dan total
jumlah kamar adalah lebih besar dari 8 kamar.
SELECT ownerNo AS Id, COUNT(propertyNo) AS Jumlah
Properti, SUM (room) AS Total Jumlah Kamar
FROM PropertyForRent
GROUP BY ownerNo
HAVING COUNT(propertyNo) >= 2 AND SUM (room) >8;

8. Tampilkan detail client yang melihat properti yang dikelola oleh seorang
manager yang bekerja di branch yang berada di kota London.
SELECT*
FROM Client
WHERE clientNo IN (
SELECT clientNo
FROM Viewing
WHERE propertyNo IN(
SELECT propertyNo
FROM PropertyForRent
WHERE staffNo IN(
SELECT staffNo
FROM Staff
WHERE position =’Manager’ AND branchNo IN(
SELECT branchNo
FROM branch
WHERE city =’London’))));
9. Tampilkan detail client yang melihat properti yang dikelola oleh seorang
staff yang mengelola lebih dari satu properti dan client melihat pada bulan
Mei.
SELECT *
FROM Client
WHERE clientNo IN (
SELECT clientNo
FROM Viewing
WHERE propertyNo IN (
SELECT propertyNo
FROM PropertyForRent
WHERE viewdate
LIKE ‘%May%’ AND staffNo IN (
SELECT StaffNo, COUNT(propertyNo)
FROM PropertyForRent
GROUP BY staffNo
HAVING COUNT(propertyNo)>1);

Potrebbero piacerti anche