MySQL SQL 練習問題
This commit is contained in:
29
MYSQL_Question2.txt
Normal file
29
MYSQL_Question2.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
--問1
|
||||
create table item_category (
|
||||
category_id INT AUTO_INCREMENT,
|
||||
category_name VARCHAR(256) not null,
|
||||
primary key(category_id)
|
||||
);
|
||||
insert into item_category values(1, '家具');
|
||||
insert into item_category values(2, '飲料');
|
||||
insert into item_category values(3, '食品');
|
||||
|
||||
--問2
|
||||
create table items(
|
||||
item_id INT AUTO_INCREMENT,
|
||||
name VARCHAR(256) not null,
|
||||
price INT not null,
|
||||
category_id INT,
|
||||
primary key(item_id),
|
||||
foreign key(category_id) references item_category(category_id)
|
||||
);
|
||||
insert into items values(1,'ローマのテーブル', 150000, 1);
|
||||
insert into items values(2,'げーたるーど2000 500ml', 370, 2);
|
||||
insert into items values(3,'原始肉', 2500, 3);
|
||||
insert into items values(4,'魅惑の椅子', 100000, 1);
|
||||
|
||||
--問3
|
||||
select * from items inner join item_category using(category_id);
|
||||
|
||||
--問4
|
||||
select * from items inner join item_category using(category_id) order by price;
|
||||
Reference in New Issue
Block a user