and bind the attribute for the file and relation.Based on our ERD, we have: Locations id, city_name Primary key id Customers id, name, email, phone_number, location, gender Primary key i
Trang 1
VIETNAM NATIONAL UNIVERSITY, HANOI INTERNATIONAL SCHOOL
DATABASE SYSTEMS Topic: DATABASE SYSTEMS FOR TRAVELOKA
Class: INS 205501
Lecturer: NGUYEN DINH TRAN LONG
GROUP 10:
Đỗ Hồng Phúc
Phan Viết Anh Quân
Lê Mạnh Hùng
traveloka
FINAL PROJECT
Trang 2
Group 10
Hanoi, December 2023
Trang 3TABLE OF CONTENT
L INTRODUCTION
1 About the Organization
2 Requirement Specification
3 Business Narrative
Il ANALYZING AND DESIGNING THE DATABASE
1 ERD
2 Relational Schema
3 Some read data and SQL script
II REPORT AND INFORMATION
1 Summary some reports and requirements for real usage
2 Requirements and Solutions
IV CONCLUSION
Trang 4I INTRODUCTION
1 About the Organization
Traveloka was established in February 2012 by three Indonesian software engineers: Ferry Unardi, Albert, and Derianto Kusuma Unardi and Albert had met while studying computer science in the United States, while Unardi met Kusuma while both were interning at
Microsoft All three ultimately worked in Silicon Valley Unardi, frequently encountering travel difficulties when visiting his hometown of Padang, came upon the idea of a website to ease travel logistics in Indonesia As he had no business experience, he began an MBA
program at Harvard Business School However, in early 2012, the Indonesian tech market was attracting international investors and e-ticketing was becoming more popular, so Unardi dropped out early and the three founders moved to Jakarta and established Traveloka
2 Requirement Specification
The information used in this report is gathered from the following sources:
a Contact:
We designed the database primarily based on information from public information about the company and sidelined information we received when we contacted them
b Researching new / dataset:
We compare and draw conclusions from some datasets that are similar to our target Some data are referenced from Kagle
3 Business Narrative
The database will solve two main activities: “managing the information of the products”,
“managing the information of all sale transactions”
The hotel management system receives room reservations and categorizes them into units
such as "Standard Rooms," "Executive Suites,” "Luxury Suites," and more To provide easily
recognizable information, the system stores details about the supplier linked to each room category Each room reservation is assigned a unique ID for easy identification and error
prevention in management This method ensures clear information about room types,
enhancing the booking experience for customers
Trang 5Group 10
“Managing the information of Sale Transactions” involves a complex system that can store
information about the Store, Products, Employees, Customers, and their VIP customers It is
responsible for keeping clear and accurate records of Operation contracts, Product Sales
agreements, Labor agreements, and Customer dates
i ERD
|
/
Figure 1: ERD
2 Relational Schema
Reservations Fk2 | Hotel_ID
FK3 | Section_ID
FK | Location_ID
Trang 6The next step is to define the attributes such as: primary key, foreign key, and bind the
attribute for the file and relation.Based on our ERD, we have:
Locations (id, city_name)
Primary key (id)
Customers (id, name, email, phone_number, location, gender)
Primary key (id),
Foreign key (Location_ID) references Locations (Location_ID)
Hotels (id, locationID, hotel_name)
Primary key (id)
Foreign key (Location_id) references Locations (Location_id)
Sections (id, sectionID, room_type)
Primary key (id)
Foreign key (Hotel_id) references hotels (Hotel_id)
Sales (id, apply_month, sale_percent)
Primary key (id)
Rooms (id, hotelID, sectionID, saleID, floor)
Primary key (id)
Foreign key (section_id) references sections (section_id)
Foreign key (hotel_id) references hotels (hotel_id)
Foreign key (sale_id) references sales (sale_id)
Reservations (id, customerID, hotelID, sectionID, roomID, dayStart, dayEnd, price)
Primary key (id)
Foreign key(CustomerID) references customers (customer_id)
Foreign key(HotelID) references hotels (hotel_id)
Foreign key(SectionID) references sections (section_id)
Foreign key(RoomID) references rooms (room_id)
Our detailed SQL statement
CREATE DATABASE Final;
USE Final,
Trang 7drop table if exists reservations;
drop table if exists rooms;
drop table if exists sales;
drop table if exists sections;
drop table if exists hotels;
drop table if exists customers;
drop table if exists locations;
create table locations
(
primary key (location_id)
b
create table customers
(
phone_number varchar(10) not null,
location_id int,
primary key (customer_id),
foreign key (location_id) references locations (location_id)
create table hotels
(
location_id int not null,
hotel_name varchar(50) default ",
Trang 8);
primary key (hotel_id),
foreign key (location_id) references locations (location_id)
create table sections
(
room_type varchar(30) not null default ",
primary key (section_id),
foreign key (hotel_id) references hotels (hotel_id)
create table sales
(
apply_month int not null,
sale percent int not null,
primary key (sale_id)
create table rooms
(
hotel_id int not null,
section_id int not null,
sale id int not null,
floor int not null,
primary key (room_id),
foreign key ( section_id) references sections (section_id),
foreign key (hotel_id) references hotels (hotel_id),
Trang 9Group 10
);
foreign key (sale_id) references sales (sale_id)
create table reservations
(
reservation_id int not null primary key,
3 Some read data and SQL script
— Results g¥ Messages
1 13000 Nguyen Duc Quang ducquang3000@gmail.com 0123458789 7000 nam
2 Le Nhat Huy nhathuy3010@gmail com 0123456780 7000 nam
Figure 3: Customer Data
Trang 10Group 10
100% x
Eä Resultls gẩ Messages
hotelid location id hotel name
1 [1100 j Royal Hotel
3 1300 7000 JW Marriott Hanoi
4 1400 7010 Tan Son Nhat Hotel
5 1500 7010 Eastin Grand Hotel Saigon
6 1600 7020 Pavilion Hotel
7 1700 7030 Vinpearl Hotel Imperia Haiphong
8 1800 7040 Muong Thanh Luxury Quang Ninh Hotel
9 1900 7060 Saphir DaLat Hotel
Figure 4: Hotel Data
100% x
FB Results cũ Messages location_id _ city
1 [7000 | Ha Noi
2 Ho Chi Minh
3 Da Nang
4 Hai Phong
5 Quang Ninh
6 Quang binh
š Da Lat
8 Hue
9 Khanh Hoa
10 7090 Lang Son
11 7110 Thanh Hoa
12 7220 Nghe An
13 7330 Bac Ninh
14 7440 Hung Yen
15 7550 Nam Dinh
16 7660 Phu Yen
17 7770 Buon Ma
18 7880 Can Tho
19 7990 Kien Giang
Figure 5 : Location Data
Trang 11Figure 6: Reservation Data
Figure 7 : Room Data
Trang 12Figure 8 : Sale Data
Figure 9 : Hotel Data
Trang 13I REPORT AND INFORMATION
1 Summary some reports and requirements for real usage
2019
descending order
level of the customer with the longest number of days staying at the hotel in Hanoi
in Hanoi
who have ever booked a room for each hotel before October 20, 2019 in descending order
e Customer name, hotel name, cheapest room id that the customer has booked in case
this person only stays 3 days
more customers booking rooms in February or December in Hanoi
2 Requirements and Solutions
2019
SELECT
h.hotel_name AS "lên Khách Sạn,
rv.room_¡d AS ID Phòng được đặt nhiều nhất trong năm 20 19',
COUNT(rv.reservation_¡đ) AS 'Số lượt đặt phong'
FROM
hotels h
JOIN
reservations rv ON h.hotel_id = rv.hotel_id
WHERE
YEAR(tv.day_ start) = 2019
GROUP BY
h.hotel_name, rv.room_id, h.hotel_id Add h.hotel_id to GROUP BY
HAVING
COUNT(rv.reservation_id) = (
SELECT TOP 1 COUNT(reservation_id)
Trang 14FROM reservations
WHERE hotel_id = h.hotel_id
GROUP BY room_id
ORDER BY COUNT(reservation_id) DESC
);
in descending order
SELECT
rv.hotel_id AS 'ID Khach San’,
h.hotel_name AS "lên Khách Sạn,
AVGf(rv.prce) AS 'Muc chi tieu trung binh cua khach san trong nam 2019 (VND}
FROM
reservations rv
JOIN
hotels h ON rv.hotel_id = h.hotel_id
WHERE
YEAR(tv.day_ start) = 2019
GROUP BY
rv.hotel_1d, h.hotel_ name
ORDER BY
AVGf(rv.price) DESC;
level of the customer with the longest number of days staying at the hotel in Hanoi
SELECT
c.name AS 'Tén Khach Hang’,
DATEDIFF(day, rv.day_start, rv.day_end) AS 'S6 ngay lun lai’,
rv.price AS 'Chi tiêu của Khách hàng'
FROM
reservations rv
JOIN
customers c ON rv.customer_id = c.customer_id
WHERE
tv.hotel_id IN (SELECT h-hotel_id
FROM hotels h
JOIN locations | ON h.location_id = Llocation_id
WHERE I.city = 'Hà Nội)
AND DATEDIFF(day, rv.day_start, rv.day_end) = (
SELECT MAX(DATEDIFF(day, day_ start, day_end))
FROM reservations
WHERE hotel_id IN (
SELECT h.hotel_id
Trang 15FROM hotels h
JOIN locations | ON h.location_id = | location_id
WHERE L.city ='Ha NO’
)
);
2019
SELECT
h.hotel_name AS "lên Khách Sạn có số lượt đặt phòng nhiều nhất tháng 12,
COUNT(rv.reservation_id) AS 'S6 lượt đặt phòng'
FROM
hotels h
JOIN
reservations rv ON h.hotel_id = rv.hotel_id
WHERE
MONTH(v.day_ start) = 12
GROUP BY
rv.hotel_1d, h.hotel_ name
HAVING
COUNT(rv.reservation_id) = (
SELECT TOP 1 COUNT(reservation_id)
FROM reservations
WHERE MONTH(day_start) = 12
GROUP BY hotel_id
ORDER BY COUNT(reservation_id) DESC
);
SELECT
h.hotel_name AS "lên Khách Sạn,
STRING AGG(r.room_id, ', ') AS 'ID Phong’,
rfloor AS 'Tang'
FROM
rooms r
JOIN
hotels h ON r.hotel_id = h-hotel_id
WHERE
r.floor = (SELECT MAX(floor)
FROM rooms
WHERE hotel_id = h.hotel_id)
GROUP BY
h.hotel_id, h.hotel_name, r-floor
Trang 16ORDER BY
r.floor DESC;
December in Hanoi
SELECT
r.room_id AS 'ID Phong’,
h.hotel_name AS "lên Khách sạn',
rfloor AS 'Tầng',
s.room_type AS 'Loai Phong’,
STRING_AGG(CONVERT(VARCHAR, sl.sale_percent) + '%',',") AS 'Mire giam gia’, sLapply_month AS 'Thang ap dung’
FROM
sales sl
JOIN
rooms r ON r.room_id =r.room_id
JOIN
sections s ON r.section_id = s.section_id
JOIN
hotels h ON r.hotel_id = h-hotel_id
WHERE
s.room_type = 'Double'
AND r.hotel_id IN (
SELECT h.hotel_id
FROM hotels h
JOIN locations | ON h.location_id = Llocation_id
WHERE Lcity = 'Ha Noi’
)
AND sl.apply_month = 12
GROUP BY
r.room_id, h-hotel_name, r-floor, s.room_type, sl.apply_month;
SELECT
h.hotel_name AS "lên Khách sạn',
AVG(sLsale_percent) AS 'Mirc giam giá trung bình tháng 1'
FROM
rooms r
INNER JOIN
hotels h ON r.hotel_id = h-hotel_id
INNER JOIN
sales sl ON r.sale_id = sl.sale_id
WHERE
Trang 17sLapply_month = |
GROUP BY
h.hotel_id, h.hotel_name;
who have ever booked a room for each hotel before October 20, 2019 in descending order
SELECT
h.hotel_name AS "lên Khách sạn',
COUNT(CASE WHEN c.gender = 'Nam' THEN 1 END) AS 'Số khách hàng Nam', COUNT(CASE WHEN c.gender = 'Nữ' THEN 1 END) AS 'Số khách hàng Nữ, COUNT(DISTINCT rv.customer_id) AS 'Téng sé khach'
FROM
reservations rv
INNER JOIN
customers c ON rv.customer_id = c.customer_id
INNER JOIN
hotels h ON rv.hotel_id = h.hotel_id
WHERE
rv.day_ start <'2019-10-20'
GROUP BY
h.hotel_id, h.-hotel_ name
ORDER BY
COUNT(DISTINCT rv.customer_id) DESC;
© Customer name, hotel name, cheapest room id that the customer has booked in
case this person only stays 3 days
SELECT
c.name AS 'Khach hang’,
h.hotel_name AS 'Tén khach san’,
rroom_¡d AS 'Số phòng',
r.price AS 'Giá tién’,
r.day_start AS 'Ngay dat phòng,
r.day_end AS 'Ngay tra phong’
FROM
customers c
JOIN
reservations r ON c.customer_id = r.customer_id
JOIN
hotels h ON r.hotel_id = h-hotel_id
WHERE
DATEDIFF(day, r.day_start, r.day_end) = 3
AND r.price = (
Trang 18SELECT MIN(price)
FROM reservations
WHERE DATEDIFF(day, day_ start, day_end) = 3
);
more customers booking rooms in February or December in Hanoi
SELECT
r.room_id AS 'ID Phong’,
h.hotel_name AS "lên Khách sạn',
s.room_type AS 'Loai phong’,
sỈ.sale_percent AS 'Mức giảm gia’,
COUNT(CASE WHEN MONTH(tv.day_start) = 2 THEN 1 END) AS 'Số lượt đặt trong thang 2’,
COUNT(CASE WHEN MONTH(tv.day_ start) = 12 THEN 1 END) AS'S6 luot dat trong thang 12'
FROM
rooms r
JOIN
reservations rv ON r.room_id=rv.room_id
JOIN
hotels h ON ry.hotel_id = h.hotel_id
JOIN
sales sl ON r.sale_id = sl.sale_id
JOIN
sections s ON r.section_id = s.section_id
WHERE
h.hotel_id IN (
SELECT h.hotel_id
FROM hotels h
JOIN locations | ON h.location_id = Llocation_id
WHERE Lcity = 'Ha Noi’
)
GROUP BY
r.room_id, h.hotel_name, s.room_type, sl.sale_percent
HAVING
COUNT(CASE WHEN MONTH(rv.day_ start) = 2 THEN 1 END) >= 2
OR COUNT(CASE WHEN MONTH(rv.day_ start) = 12 THEN 1 END) >= 2;
To conclude the project, I hereby summarize some of the plus points and also the downsides
of the database built by our group as follows:
Trang 191 Advantages of the project to the business:
how many partners they are working with
The database provides a much more scientific way of managing the amount of items and which item is available
The database provides a clearer view of the flow of product - from the store to its customer then to the second customer
ERD provides the business a better view of relations between all of the subjects
The database provides a better way to audit the shop’s data compared to pens and papers
With a database, traveloka stores can track customer preferences and purchase history to provide more personalized recommendations and promotions This can help build customer loyalty and increase sales
°
°
There are not many types of data that can be inserted in
This database lacks real information, there are only 20 samples for each table, not more, it would be better for the real business if there was more
information
This database lacks options for auditing the items that customers buy and also the quantity bought by them
This project will help the business a big deal in storing data and manage the basic data but not very ideal for auditing