More Related Content Similar to W7 57-010126-2009-8 Similar to W7 57-010126-2009-8 (20) W7 57-010126-2009-88. Solution
code : cinemas
CREATE TABLE `cinemas` (
`c_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`c_name` CHAR(50) NOT NULL DEFAULT '0',
PRIMARY KEY (`c_id`)
);
9. Solution
code : theaters
CREATE TABLE `theaters` (
`t_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`t_num` INT(10) NOT NULL,
`seat_cap` INT(10) UNSIGNED NOT NULL,
`c_id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`t_id`),
INDEX `c_id` (`c_id`),
CONSTRAINT `c_id` FOREIGN KEY (`c_id`) REFERENCES `cinemas` (`c_id`)
);
10. Solution
code : theaters
CREATE TABLE `movies` (
`m_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`m_name` CHAR(50) NULL DEFAULT '0',
`m_release` DATE NOT NULL,
PRIMARY KEY (`m_id`)
);
11. Solution
code : theaters
CREATE TABLE `shows` (
`t_id` INT(10) UNSIGNED NOT NULL,
`m_id` INT(10) UNSIGNED NOT NULL,
`time_slot` DATETIME NOT NULL,
`price` INT(11) UNSIGNED NOT NULL,
`num_adult` INT(11) UNSIGNED NOT NULL,
`num_child` INT(11) UNSIGNED NOT NULL,
INDEX `t_id` (`t_id`),
INDEX `m_id` (`m_id`),
CONSTRAINT `m_id` FOREIGN KEY (`m_id`) REFERENCES `movies` (`m_id`),
CONSTRAINT `t_id` FOREIGN KEY (`t_id`) REFERENCES `theaters` (`t_id`)
);
27. Result
The program generated
- 19 rows of data for table “cinemas”
- 530 rows of data for table “movies”
- 541,457 rows of data for table “shows”
- 208 rows of data for table “theaters”
31. #2 Query
select
cinemas.c_name,
movies.m_name,
theaters.t_num,
shows.time_slot,
round((shows.num_adult / (shows.num_adult + shows.num_child)) * 100) as percent_adult,
round((shows.num_child / (shows.num_adult + shows.num_child)) * 100) as percent_child,
shows.price*(shows.num_adult + shows.num_child) as income
from shows
inner join movies on shows.m_id = movies.m_id
inner join theaters on theaters.t_id = shows.t_id
inner join cinemas on cinemas.c_id = theaters.c_id
order by c_name,m_name,time_slot,t_num,price;
33. #3 Query
select
cinemas.c_name,
movies.m_name,
theaters.t_num,
shows.time_slot,
shows.price,
round((shows.num_adult / (shows.num_adult + shows.num_child)) * 100) as percent_adult,
round((shows.num_child / (shows.num_adult + shows.num_child)) * 100) as percent_child,
shows.price*(shows.num_adult + shows.num_child) as income
from shows
inner join movies on shows.m_id = movies.m_id
inner join theaters on theaters.t_id = shows.t_id
inner join cinemas on cinemas.c_id = theaters.c_id
order by c_name,m_name,time_slot,t_num,price;
35. #4 Query
select
cinemas.c_name,
movies.m_name,
theaters.t_num,
shows.time_slot,
shows.price,
shows.num_adult,
shows.num_child,
shows.num_adult + shows.num_child as num_customers,
theaters.seat_cap,
round((shows.num_adult / (shows.num_adult + shows.num_child)) * 100) as percent_adult,
round((shows.num_child / (shows.num_adult + shows.num_child)) * 100) as percent_child,
shows.price*(shows.num_adult + shows.num_child) as income
from shows
inner join movies on shows.m_id = movies.m_id
inner join theaters on theaters.t_id = shows.t_id
inner join cinemas on cinemas.c_id = theaters.c_id
order by c_name,m_name,time_slot,t_num,price;