-
Notifications
You must be signed in to change notification settings - Fork 3
/
datascript.sql
122 lines (95 loc) · 4.77 KB
/
datascript.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
DROP TABLE IF EXISTS `User`;
CREATE TABLE `User` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`first_name` VARCHAR(16) NULL DEFAULT NULL,
`last_name` VARCHAR(16) NULL DEFAULT NULL,
`phone` VARCHAR(16) NULL DEFAULT NULL,
`email` VARCHAR(36) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `BookingJournal`;
CREATE TABLE `BookingJournal` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`user_id` BIGINT NULL DEFAULT NULL,
`room_id` BIGINT NULL DEFAULT NULL,
`date_from` DATE(36) NULL DEFAULT NULL,
`date_to` DATE(36) NULL DEFAULT NULL,
`total_price` DOUBLE(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `Room`;
CREATE TABLE `Room` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`category_id` BIGINT NULL DEFAULT NULL,
`number` VARCHAR(6) NULL DEFAULT NULL,
`price` DOUBLE(6) NULL DEFAULT NULL,
`available` INTEGER(1) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `Features`;
CREATE TABLE `Features` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(36) NULL DEFAULT NULL,
`price` DOUBLE(6) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `journal2features`;
CREATE TABLE `journal2features` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`BookingJournal_id` INTEGER NULL DEFAULT NULL,
`features_id` INTEGER NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `Category`;
CREATE TABLE `Category` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`category_room` VARCHAR(16) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
ALTER TABLE `BookingJournal` ADD FOREIGN KEY (user_id) REFERENCES `User` (`id`);
ALTER TABLE `BookingJournal` ADD FOREIGN KEY (room_id) REFERENCES `Room` (`id`);
ALTER TABLE `Room` ADD FOREIGN KEY (category_id) REFERENCES `Category` (`id`);
ALTER TABLE `journal2features` ADD FOREIGN KEY (bookingJournal_id) REFERENCES `BookingJournal` (`id`);
ALTER TABLE `journal2features` ADD FOREIGN KEY (features_id) REFERENCES `Features` (`id`);
SELECT * FROM USER;
INSERT INTO `User` (`id`,`first_name`,`last_name`,`phone`,`email`) VALUES ('1','Sasha1','Bogush1','1969601256','sashabogush1@ukr.sfg');
INSERT INTO `User` (`id`,`first_name`,`last_name`,`phone`,`email`) VALUES ('2','Sasha2','Bogush2','2969601256','sashabogush2@ukr.sfg');
INSERT INTO `User` (`id`,`first_name`,`last_name`,`phone`,`email`) VALUES ('3','Sasha3','Bogush3','2969601256','sashabogush3@ukr.sfg');
INSERT INTO `User` (`id`,`first_name`,`last_name`,`phone`,`email`) VALUES ('4','Sasha4','Bogush4','2969601256','sashabogush4@ukr.sfg');
SELECT * FROM USER;
SELECT * FROM CATEGORY ;
INSERT INTO `CATEGORY` (`id`,`category_room`) VALUES ('1','KINGROOM');
INSERT INTO `CATEGORY` (`id`,`category_room`) VALUES ('2','LOSERROOM');
INSERT INTO `CATEGORY` (`id`,`category_room`) VALUES ('3','LUXROOM');
SELECT * FROM CATEGORY ;
SELECT * FROM FEATURES ;
INSERT INTO `Features` (`id`,`name`,`price`) VALUES ('1','ZAVTRAK','65.33');
INSERT INTO `Features` (`id`,`name`,`price`) VALUES ('2','DINER','656.32');
INSERT INTO `Features` (`id`,`name`,`price`) VALUES ('3','UBORKA','150.96');
INSERT INTO `Features` (`id`,`name`,`price`) VALUES ('4','BAR','500.03');
SELECT * FROM FEATURES ;
SELECT * FROM ROOM;
INSERT INTO `ROOM` (`id`,`category_id`,`number`,`price`,`available`) VALUES ('1','1','1A','32.56','1');
INSERT INTO `ROOM` (`id`,`category_id`,`number`,`price`,`available`) VALUES ('2','2','2A','362.56','0');
INSERT INTO `ROOM` (`id`,`category_id`,`number`,`price`,`available`) VALUES ('3','3','3A','2.56','1');
INSERT INTO `ROOM` (`id`,`category_id`,`number`,`price`,`available`) VALUES ('4','1','1B','62.56','0');
INSERT INTO `ROOM` (`id`,`category_id`,`number`,`price`,`available`) VALUES ('5','2','2B','32.56','1');
SELECT * FROM ROOM;
SELECT * FROM BOOKINGJOURNAL;
INSERT INTO `BOOKINGJOURNAL` (`id`,`user_id`,`room_id`,`date_from`,`date_to`,`total_price`) VALUES ('1','1','1','2019-2-1','2022-1-1','9200.01');
INSERT INTO `BOOKINGJOURNAL` (`id`,`user_id`,`room_id`,`date_from`,`date_to`,`total_price`) VALUES ('2','2','2','2019-12-1','2020-1-1','9000.01');
INSERT INTO `BOOKINGJOURNAL` (`id`,`user_id`,`room_id`,`date_from`,`date_to`,`total_price`) VALUES ('3','3','3','2018-12-1','2020-1-1','3600.01');
SELECT * FROM BOOKINGJOURNAL ;
SELECT * FROM JOURNAL2FEATURES ;
INSERT INTO `JOURNAL2FEATURES` (`id`,`bookingJournal_id`,`features_id`) VALUES ('1','1','1');
INSERT INTO `JOURNAL2FEATURES` (`id`,`bookingJournal_id`,`features_id`) VALUES ('2','2','2');
INSERT INTO `JOURNAL2FEATURES` (`id`,`bookingJournal_id`,`features_id`) VALUES ('3','3','3');
SELECT * FROM JOURNAL2FEATURES ;
select room.id, category_room, number, price, available from room
join category
on category.id = category_id;
select room.id, category_room, number, price, available from room
join category
on category.id = category_id;
select user_id, sum(total_price) from bookingjournal
group by user_id;