Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c328ae16e |
@@ -1,32 +0,0 @@
|
||||
--問1
|
||||
CREATE TABLE book_table (
|
||||
book_id INT,
|
||||
book_name VARCHAR(50),
|
||||
author_name VARCHAR(50),
|
||||
price INT,
|
||||
sales_flag INT
|
||||
);
|
||||
|
||||
--問2
|
||||
INSERT INTO book_table VALUES(10001, 'TwoPeace', '三田英一郎', 420, 1);
|
||||
INSERT INTO book_table VALUES(10002, '名探偵金田二', '青山ふみや', 460, 1);
|
||||
INSERT INTO book_table VALUES(20001, '坊ちゃま', '冬目漱岩', 460, 1);
|
||||
INSERT INTO book_table VALUES(30001, '西方見聞録', '不明', 1000, 1);
|
||||
INSERT INTO book_table VALUES(40010, '吾輩は犬である', '冬目漱岩', 420
|
||||
, 1);
|
||||
|
||||
--問3
|
||||
SELECT book_name, author_name FROM book_table;
|
||||
|
||||
--問4
|
||||
UPDATE book_table SET author_name = 'マール=コー=ポロ', sales_flag = 0 WHERE book_id = 30001;
|
||||
|
||||
--問5
|
||||
select book_id, book_name, author_name, price, sales_flag from book_table where sales_flag = 1;
|
||||
|
||||
--問6
|
||||
select book_id, book_name, author_name, price, sales_flag from book_table where author_name = '冬目漱岩' and price = 420;
|
||||
|
||||
--問7
|
||||
delete from book_table where book_id = 20001;
|
||||
select * from book_table;
|
||||
@@ -1,29 +0,0 @@
|
||||
--問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;
|
||||
@@ -1,14 +0,0 @@
|
||||
--問5
|
||||
select * from items inner join item_category using(category_id) where category_name = '家具';
|
||||
|
||||
--問6
|
||||
select * from items inner join item_category using(category_id) where price between 1000 and 50000;
|
||||
|
||||
--問7
|
||||
select count(*) as data_count from items;
|
||||
|
||||
--問8
|
||||
select * from items inner join item_category using(category_id) where price = (select max(price) from items);
|
||||
|
||||
--問9
|
||||
select * from items inner join item_category using(category_id) where name like '%の%';
|
||||
@@ -1,10 +0,0 @@
|
||||
--問1
|
||||
select items.item_id as 商品ID, items.name as 商品名, items.price as 価格,
|
||||
item_category.name as カテゴリ名 from items inner join item_category using(category_id);
|
||||
|
||||
--問2
|
||||
select orders.order_id as 注文ID, orders.order_time as 注文日時, users.name as ユーザー名,
|
||||
items.name as 商品名, items.price as 価格, order_items.quantity as 数量 from order_items
|
||||
inner join orders using(order_id)
|
||||
inner join items using(item_id)
|
||||
inner join users using(user_id) order by orders.order_time;
|
||||
@@ -111,4 +111,31 @@ INSERT INTO order_items (order_id, item_id, quantity) VALUES (9, 3, 4);
|
||||
INSERT INTO order_items (order_id, item_id, quantity) VALUES (9, 5, 2);
|
||||
INSERT INTO order_items (order_id, item_id, quantity) VALUES (9, 8, 10);
|
||||
INSERT INTO order_items (order_id, item_id, quantity) VALUES (10, 1, 2);
|
||||
INSERT INTO order_items (order_id, item_id, quantity) VALUES (10, 10, 2);
|
||||
INSERT INTO order_items (order_id, item_id, quantity) VALUES (10, 10, 2);
|
||||
|
||||
--Q1--
|
||||
SELECT items.item_id AS '商品ID', items.name AS '商品名',items.price AS '価格',item_category.name AS 'カテゴリ名' FROM items
|
||||
LEFT OUTER JOIN item_category ON item_category.category_id = items.category_id;
|
||||
|
||||
|
||||
--Q2--
|
||||
SELECT orders.order_id AS '注文ID',orders.order_time AS '注文日時', users.name AS 'ユーザ名',items.name AS '商品名',items.price AS '価格', order_items.quantity AS '数量'
|
||||
FROM order_items
|
||||
INNER JOIN orders ON orders.order_id = order_items.order_id
|
||||
INNER JOIN users ON users.user_id = orders.user_id
|
||||
INNER JOIN items ON items.item_id = order_items.item_id
|
||||
ORDER BY orders.order_time ASC;
|
||||
|
||||
|
||||
--Q3--
|
||||
SELECT orders.order_id AS '注文ID',orders.order_time AS '注文日時',users.name AS 'ユーザ名',
|
||||
SUM(items.price * order_items.quantity) AS '合計額'
|
||||
FROM orders
|
||||
INNER JOIN users ON users.user_id = orders.user_id
|
||||
INNER JOIN order_items ON order_items.order_id = orders.order_id
|
||||
INNER JOIN items ON items.item_id = order_items.item_id
|
||||
GROUP BY orders.order_id,orders.order_time,users.name
|
||||
ORDER BY orders.order_time ASC;
|
||||
|
||||
--Q4--
|
||||
SELECT
|
||||
|
||||
21
SQL/kougi.sql
Normal file
21
SQL/kougi.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE emp_table (
|
||||
emp_no INT,
|
||||
emp_name VARCHAR(50),
|
||||
salary INT
|
||||
);
|
||||
|
||||
--<EFBFBD>o<EFBFBD>^
|
||||
INSERT INTO emp_table VALUES(1,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',200000);
|
||||
INSERT INTO emp_table VALUES(2,'<EFBFBD>c<EFBFBD><EFBFBD>',500000);
|
||||
|
||||
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
SELECT * FROM emp_table;
|
||||
SELECT * FROM emp_table WHERE emp_no = 1;
|
||||
|
||||
--<EFBFBD>X<EFBFBD>V
|
||||
UPDATE emp_table SET salary = 100;
|
||||
SELECT * FROM emp_table;
|
||||
|
||||
--<EFBFBD>폜
|
||||
DELETE FROM emp_table;
|
||||
SELECT * FROM emp_table;
|
||||
25
SQL/q1.sql
Normal file
25
SQL/q1.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
CREATE TABLE book_table (
|
||||
book_id INT,
|
||||
book_name VARCHAR(50),
|
||||
author_name VARCHAR(50),
|
||||
price INT,
|
||||
sales_flag INT
|
||||
);
|
||||
|
||||
INSERT INTO book_table VALUES (10001,'TwoPeace','<EFBFBD>O<EFBFBD>c<EFBFBD>p<EFBFBD><EFBFBD><EFBFBD>Y',420,'1');
|
||||
INSERT INTO book_table VALUES (10002,'<EFBFBD><EFBFBD><EFBFBD>T<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>c<EFBFBD><EFBFBD>','<EFBFBD>R<EFBFBD>ӂ݂<EFBFBD>',460,'1');
|
||||
INSERT INTO book_table VALUES (20001,'<EFBFBD>V<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<EFBFBD>~<7E>ڐ<EFBFBD><DA90><EFBFBD>',460,'1');
|
||||
INSERT INTO book_table VALUES (30001,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>^','<EFBFBD>s<EFBFBD><EFBFBD>',1000,'1');
|
||||
INSERT INTO book_table VALUES (40001,'<EFBFBD><EFBFBD><EFBFBD>y<EFBFBD>͌<EFBFBD><EFBFBD>ł<EFBFBD><EFBFBD><EFBFBD>','<EFBFBD>~<7E>ڐ<EFBFBD><DA90><EFBFBD>',420,'1');
|
||||
|
||||
DELETE FROM book_table WHERE book_id = 10001;
|
||||
DELETE FROM book_table;
|
||||
|
||||
SELECT book_name,author_name FROM book_table;
|
||||
|
||||
UPDATE book_table SET author_name = '<EFBFBD>}<7D>[<5B><><EFBFBD><EFBFBD><EFBFBD>R<EFBFBD>[<5B><><EFBFBD>|<7C><>' WHERE book_id = 30001;
|
||||
UPDATE book_table SET sales_flag = '0' WHERE book_id = 30001;
|
||||
|
||||
SELECT * FROM book_table HAVING sales_flag = '1';
|
||||
|
||||
DELETE FROM book_table WHERE book_id = 20001;
|
||||
6
SQL/q2+.sql
Normal file
6
SQL/q2+.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE DATABASE Q2Extends ;
|
||||
show databases;
|
||||
|
||||
|
||||
--Q1--
|
||||
CREATE TABLE syouhine
|
||||
50
SQL/q2.sql
Normal file
50
SQL/q2.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
CREATE TABLE item_category (
|
||||
category_id INT PRIMARY KEY AUTO_INCREMENT COMMENT '<EFBFBD>J<EFBFBD>e<EFBFBD>S<EFBFBD><EFBFBD>ID',
|
||||
category_name VARCHAR(256) NOT NULL COMMENT '<EFBFBD>J<EFBFBD>e<EFBFBD>S<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
|
||||
);
|
||||
|
||||
|
||||
INSERT INTO item_category VALUES (1,'<EFBFBD>Ƌ<EFBFBD>');
|
||||
INSERT INTO item_category VALUES (2,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||||
INSERT INTO item_category VALUES (3,'<EFBFBD>H<EFBFBD>i');
|
||||
|
||||
|
||||
CREATE TABLE items (
|
||||
item_id INT PRIMARY KEY AUTO_INCREMENT COMMENT '<EFBFBD>A<EFBFBD>C<EFBFBD>e<EFBFBD><EFBFBD>ID',
|
||||
name VARCHAR(256) NOT NULL COMMENT '<EFBFBD>A<EFBFBD>C<EFBFBD>e<EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
|
||||
price INT NOT NULL COMMENT '<EFBFBD><EFBFBD><EFBFBD>i',
|
||||
category_id INT COMMENT '<EFBFBD>J<EFBFBD>e<EFBFBD>S<EFBFBD><EFBFBD>ID',
|
||||
FOREIGN KEY (category_id) REFERENCES item_category(category_id)
|
||||
);
|
||||
|
||||
INSERT INTO items VALUES (1,'<EFBFBD><EFBFBD><EFBFBD>[<5B>}<7D>̃e<CC83>[<5B>u<EFBFBD><75>',150000,1);
|
||||
INSERT INTO items VALUES (2,'<EFBFBD><EFBFBD><EFBFBD>[<5B><><EFBFBD><EFBFBD><EFBFBD>[<5B><>2000 500ml',370,2);
|
||||
INSERT INTO items VALUES (3,'<EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><EFBFBD>',2500,3);
|
||||
INSERT INTO items VALUES (4,'<EFBFBD><EFBFBD><EFBFBD>f<EFBFBD>̈֎q',100000,1);
|
||||
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id;
|
||||
|
||||
UPDATE items SET price = 100000 WHERE items.name = '<EFBFBD><EFBFBD><EFBFBD>f<EFBFBD>̈֎q';
|
||||
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id
|
||||
ORDER BY items.price;
|
||||
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id WHERE item_category.category_id = 1;
|
||||
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id WHERE items.price >=1000 and items.price <=50000;
|
||||
|
||||
SELECT COUNT(*)AS data_count FROM items;
|
||||
|
||||
--Q8--
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id
|
||||
WHERE items.price = (SELECT MAX(price) FROM items);
|
||||
|
||||
---Q9---
|
||||
SELECT item_category.category_id,items.item_id,items.name,items.price,item_category.category_name AS name
|
||||
FROM item_category LEFT OUTER JOIN items ON items.category_id = item_category.category_id
|
||||
WHERE items.name LIKE '%<25><>%';
|
||||
Reference in New Issue
Block a user