From 9552ee450513d53aa1e39eb696432826993dda58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8E=9F=E3=80=80=E5=8F=B6=E5=A4=A7?= <26-k-ishihara-acrowavenet@it-college.co.jp> Date: Tue, 27 Oct 2026 17:27:13 +0900 Subject: [PATCH] 10/27 --- Question2/ã€�+α】SQL/MySQL_question2.sql | 5 +- ç·´ç¿’å•�題/Part1.sql | 38 +++++ ç·´ç¿’å•�題/Part2.sql | 63 ++++++++ ç·´ç¿’å•�題/Part2α.sql | 99 ++++++++++++ ç·´ç¿’å•�題/Part3.1.1.sql | 51 ++++++ ç·´ç¿’å•�題/Part3.1.2.sql | 201 ++++++++++++++++++++++++ ç·´ç¿’å•�題/Part3.1.3.sql | 63 ++++++++ ç·´ç¿’å•�題/Part3.1.4.sql | 24 +++ ç·´ç¿’å•�題/Part3.1.5.sql | 27 ++++ ç·´ç¿’å•�題/Part3.1.6.sql | 36 +++++ ç·´ç¿’å•�題/Part3.1.7.sql | 57 +++++++ ç·´ç¿’å•�題/Part3.2.sql | 53 +++++++ ç·´ç¿’å•�題/サンプル.sql | 21 +++ 13 files changed, 737 insertions(+), 1 deletion(-) create mode 100644 ç·´ç¿’å•�題/Part1.sql create mode 100644 ç·´ç¿’å•�題/Part2.sql create mode 100644 ç·´ç¿’å•�題/Part2α.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.1.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.2.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.3.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.4.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.5.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.6.sql create mode 100644 ç·´ç¿’å•�題/Part3.1.7.sql create mode 100644 ç·´ç¿’å•�題/Part3.2.sql create mode 100644 ç·´ç¿’å•�題/サンプル.sql diff --git a/Question2/ã€�+α】SQL/MySQL_question2.sql b/Question2/ã€�+α】SQL/MySQL_question2.sql index 6d76a65..ec74541 100644 --- a/Question2/ã€�+α】SQL/MySQL_question2.sql +++ b/Question2/ã€�+α】SQL/MySQL_question2.sql @@ -111,4 +111,7 @@ 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); \ No newline at end of file +INSERT INTO order_items (order_id, item_id, quantity) VALUES (10, 10, 2); + + + diff --git a/ç·´ç¿’å•�題/Part1.sql b/ç·´ç¿’å•�題/Part1.sql new file mode 100644 index 0000000..5f0ebe4 --- /dev/null +++ b/ç·´ç¿’å•�題/Part1.sql @@ -0,0 +1,38 @@ +--ƒe�[ƒuƒ‹�ì�¬ +CREATE TABLE book_table ( + book_no INT COMMENT '�‘�ÐID', + book_name VARCHAR(50) COMMENT '�‘�Ж¼', + author_name VARCHAR(50) COMMENT '’˜ŽÒ–¼', + price INT COMMENT '‰¿Ši', + sales_flag INT COMMENT '”Ì”„—L–³' +); + + +--ƒf�[ƒ^“o˜^ + INSERT INTO book_table VALUES(10001, 'TwoPeace', 'ŽO“c‰pˆê˜Y', 420, 1); + INSERT INTO book_table VALUES(10002, '–¼’T’ã‹à“c“ñ', '�ÂŽR‚Ó‚Ý‚â', 460, 1); + INSERT INTO book_table VALUES(20001, '–V‚¿‚á‚Ü', '“~–ÚŸùŠâ', 460, 1); + INSERT INTO book_table VALUES(30001, '�¼•ûŒ©•·˜^', '•s–¾', 1000, 1); + INSERT INTO book_table VALUES(40010, 'Œá”y‚ÍŒ¢‚Å‚ ‚é', '“~–ÚŸùŠâ', 420, 1); + + +--Žw’èƒf�[ƒ^’Š�o + SELECT book_name, author_name FROM book_table; + + +--ƒf�[ƒ^�X�V + UPDATE book_table SET author_name = 'ƒ}�[ƒ‹ƒjƒR�[ƒjƒ|ƒ�', sales_flag = 0 WHERE book_no = 30001; + + +--“Á’èƒf�[ƒ^’Š�o + SELECT * FROM book_table WHERE sales_flag = 1; + + +--•¡�”�ðŒ�’Š�o + SELECT * FROM book_table WHERE price = 420 and author_name = '“~–ÚŸùŠâ'; + +--�í�œ + DELETE FROM book_table WHERE book_no = 20001; + + DROP TABLE book_table; + diff --git a/ç·´ç¿’å•�題/Part2.sql b/ç·´ç¿’å•�題/Part2.sql new file mode 100644 index 0000000..f938ac5 --- /dev/null +++ b/ç·´ç¿’å•�題/Part2.sql @@ -0,0 +1,63 @@ +--ƒe�[ƒuƒ‹�ì�¬ +CREATE TABLE item_category ( + category_id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ƒJƒeƒSƒŠID', + category_name VARCHAR(256) NOT NULL COMMENT 'ƒJƒeƒSƒŠ–¼' +); + +--ƒf�[ƒ^“o˜^ + INSERT INTO item_category VALUES(NULL, '‰Æ‹ï'); + INSERT INTO item_category VALUES(NULL, 'ˆù—¿'); + INSERT INTO item_category VALUES(NULL, '�H•i'); + + +--ƒe�[ƒuƒ‹�ì�¬2 +CREATE TABLE items ( + item_id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ƒAƒCƒeƒ€ID', + name VARCHAR(256) NOT NULL COMMENT 'ƒAƒCƒeƒ€–¼', + price INT NOT NULL COMMENT '‰¿Ši', + category_id INT COMMENT 'ƒJƒeƒSƒŠID', + FOREIGN KEY (category_id) + REFERENCES item_category(category_id) +); + +--“o˜^ + INSERT INTO items VALUES(NULL, 'ƒ��[ƒ}‚̃e�[ƒuƒ‹', 150000, 1); + INSERT INTO items VALUES(NULL, '‚°�[‚½‚é�[‚Ç2000 500ml', 370, 2); + INSERT INTO items VALUES(NULL, 'Œ´“_ˆ¹', 2500, 3); + INSERT INTO items VALUES(NULL, '–£˜f‚̈֎q', 100000, 1); + + +--–â3,4,5 + SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name + FROM items + INNER JOIN item_category + ON items.category_id = item_category.category_id + WHERE item_category.category_name = '‰Æ‹ï' + ORDER BY items.price ASC; + +---–â6 + SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name + FROM items + INNER JOIN item_category + ON items.category_id = item_category.category_id + WHERE items.price BETWEEN 1000 AND 50000; + + --–â7 + SELECT COUNT (*) AS data_count FROM items; + +--–â8 + SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name + FROM items + INNER JOIN item_category + ON items.category_id = item_category.category_id + WHERE items.price = (SELECT MAX(price) FROM items); + +--–â9 + SELECT items.category_id, items.item_id, items.name, items.price, item_category.category_name + FROM items + INNER JOIN item_category + ON items.category_id = item_category.category_id + WHERE items.name LIKE '%‚Ì%'; + + + diff --git a/ç·´ç¿’å•�題/Part2α.sql b/ç·´ç¿’å•�題/Part2α.sql new file mode 100644 index 0000000..a6bf25b --- /dev/null +++ b/ç·´ç¿’å•�題/Part2α.sql @@ -0,0 +1,99 @@ +--1 + SELECT items.item_id, items.name, items.price, item_category.name + FROM items + INNER JOIN item_category + ON items.category_id = item_category.category_id + ORDER BY items.item_id; + +--2 + SELECT orders.order_id, orders.order_time, users.name, items.name, items.price, order_items.quantity + FROM orders + INNER JOIN users + ON orders.user_id = users.user_id + INNER JOIN order_items + ON orders.order_id = order_items.order_id + INNER JOIN items + ON order_items.item_id = items.item_id + ORDER BY orders.order_time; + +--3 + SELECT orders.order_id, orders.order_time, users.name, SUM(items.price * order_items.quantity) AS total_price + FROM orders + INNER JOIN users + ON orders.user_id = users.user_id + INNER JOIN order_items + ON orders.order_id = order_items.order_id + INNER JOIN items + ON order_items.item_id = items.item_id + GROUP BY orders.order_id, orders.order_time, users.name + ORDER BY orders.order_time; + +--4 + SELECT DATE_FORMAT(orders.order_time, '%Y/%m') AS order_month, SUM(order_items.quantity) AS order_count + FROM orders + INNER JOIN order_items + ON orders.order_id = order_items.order_id + GROUP BY DATE_FORMAT(orders.order_time, '%Y/%m') + ORDER BY DATE_FORMAT(orders.order_time, '%Y/%m'); + +--5 + SELECT DATE_FORMAT(orders.order_time, '%Y') AS order_year, SUM(items.price * order_items.quantity) AS sales_amount + FROM orders + INNER JOIN order_items + ON orders.order_id = order_items.order_id + INNER JOIN items + ON order_items.item_id = items.item_id + GROUP BY DATE_FORMAT(orders.order_time, '%Y') + ORDER BY DATE_FORMAT(orders.order_time, '%Y'); + +--6 + SELECT SUM(items.price * order_items.quantity) AS sales_amount + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id; + +--7 + SELECT item_category.name, SUM(items.price * order_items.quantity) AS sales_amount + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id + INNER JOIN item_category + ON items.category_id = item_category.category_id + GROUP BY item_category.name; + +--8 + SELECT items.name, SUM(items.price * order_items.quantity) AS sales_amount + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id + GROUP BY items.name + ORDER BY sales_amount DESC; + +--9 + SELECT item_category.name, SUM(items.price * order_items.quantity) + / (SELECT SUM(items.price * order_items.quantity) + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id) + * 100 AS ratio + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id + INNER JOIN item_category + ON items.category_id = item_category.category_id + GROUP BY item_category.name + ORDER BY ratio DESC; + +--10 + SELECT items.name, SUM(items.price * order_items.quantity) + / (SELECT SUM(items.price * order_items.quantity) + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id) + * 100 AS ratio + FROM order_items + INNER JOIN items + ON order_items.item_id = items.item_id + GROUP BY items.name + ORDER BY ratio DESC; + diff --git a/ç·´ç¿’å•�題/Part3.1.1.sql b/ç·´ç¿’å•�題/Part3.1.1.sql new file mode 100644 index 0000000..122a526 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.1.sql @@ -0,0 +1,51 @@ +--ŠeŽíƒ}ƒXƒ^�[ƒe�[ƒuƒ‹ + CREATE TABLE pay_div_m (pay_div_cd VARCHAR(5) PRIMARY KEY, pay_div_nm VARCHAR(20)); + CREATE TABLE gender_m (gender_cd VARCHAR(2) PRIMARY KEY, gender_div_nm VARCHAR(10)); + CREATE TABLE credit_div_m (credit_div_cd VARCHAR(5) PRIMARY KEY, credit_div_nm VARCHAR(30)); + CREATE TABLE goods_div_m (goods_div_cd VARCHAR(5) PRIMARY KEY, goods_div_nm VARCHAR(30)); + CREATE TABLE tax_m (app_date DATE PRIMARY KEY, tax_rate INT); + CREATE TABLE order_sts_m (sts_cd VARCHAR(6) PRIMARY KEY, sts VARCHAR(20)); + + +--ƒŒƒR�[ƒh +--Žx•¥‚¢Ží•Ê + INSERT INTO pay_div_m VALUES ('PY001', 'ƒNƒŒƒWƒbƒgƒJ�[ƒh'); + INSERT INTO pay_div_m VALUES ('PY002', '‹â�s�U�ž'); + INSERT INTO pay_div_m VALUES ('PY003', 'ƒRƒ“ƒrƒjŒˆ�Ï'); + INSERT INTO pay_div_m VALUES ('PY004', '‘ãˆø'); + +--�«•ʃ}ƒXƒ^ + INSERT INTO gender_m VALUES ('J0', '’j�«'); + INSERT INTO gender_m VALUES ('J1', '�—�«'); + INSERT INTO gender_m VALUES ('J9', '‚»‚Ì‘¼'); + +--ƒNƒŒƒWƒbƒgƒJ�[ƒh•ª—Þ + INSERT INTO credit_div_m VALUES ('CD001', 'VISA'); + INSERT INTO credit_div_m VALUES ('CD002', 'JCB'); + INSERT INTO credit_div_m VALUES ('CD003', 'Master'); + INSERT INTO credit_div_m VALUES ('CD004', 'AMERICAN EXPRESS'); + +--�¤•i•ª—Þƒ}ƒXƒ^ + INSERT INTO goods_div_m VALUES ('K0001', '“ú—p•i'); + INSERT INTO goods_div_m VALUES ('K0002', 'ƒpƒ\ƒRƒ“�EƒIƒtƒBƒX—p•i'); + INSERT INTO goods_div_m VALUES ('K0003', 'ƒXƒ|�[ƒc�•ƒAƒEƒgƒhƒA'); + INSERT INTO goods_div_m VALUES ('K0004', 'ƒJ�[—p•i'); + INSERT INTO goods_div_m VALUES ('K0005', '�H—¿•i'); + INSERT INTO goods_div_m VALUES ('K0006', '‰Æ“d'); + INSERT INTO goods_div_m VALUES ('K0007', 'ƒtƒ@ƒbƒVƒ‡ƒ“'); + INSERT INTO goods_div_m VALUES ('K0008', 'ŒâŠy'); + +--�Á”ï�Ń}ƒXƒ^ + INSERT INTO tax_m VALUES ('1989-04-01', 3); + INSERT INTO tax_m VALUES ('1997-04-01', 5); + INSERT INTO tax_m VALUES ('2014-04-01', 8); + INSERT INTO tax_m VALUES ('2019-10-01', 10); + +--’�•¶ƒXƒe�[ƒ^ƒX + INSERT INTO order_sts_m VALUES ('STS001', 'Žó’��Ï'); + INSERT INTO order_sts_m VALUES ('STS002', '“ü‰×‘Ò'); + INSERT INTO order_sts_m VALUES ('STS003', '”­‘—�€”õ'); + INSERT INTO order_sts_m VALUES ('STS004', '”z‘—’†'); + INSERT INTO order_sts_m VALUES ('STS010', '‚¨‹q—lŽóŽæ�Ï'); + INSERT INTO order_sts_m VALUES ('STS999', 'ƒLƒƒƒ“ƒZƒ‹'); + diff --git a/ç·´ç¿’å•�題/Part3.1.2.sql b/ç·´ç¿’å•�題/Part3.1.2.sql new file mode 100644 index 0000000..89d27dd --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.2.sql @@ -0,0 +1,201 @@ +--ŒÚ‹qƒ}ƒXƒ^ + + CREATE TABLE user_m ( + user_id VARCHAR(10) PRIMARY KEY, + user_f_nm VARCHAR(20), + user_f_nm_kn VARCHAR(20), + user_nm VARCHAR(20), + user_nm_kn VARCHAR(20), + user_birth DATE, + gender_cd VARCHAR(2), + mail_address VARCHAR(100), + user_post_no VARCHAR(10), + user_prefecture_nm VARCHAR(20), + user_municipality_nm VARCHAR(50), + user_city_nm VARCHAR(50), + user_address VARCHAR(100), + user_building_nm VARCHAR(100), + user_tel_no VARCHAR(20), + user_passwd VARCHAR(20) + ); + + CREATE TABLE credit_card_t ( + user_id VARCHAR(10), + credit_div_cd VARCHAR(5), + credit_no VARCHAR(30), + credit_nm VARCHAR(50), + validated_month VARCHAR(2), + validated_year INT, + sc_cd VARCHAR(5), + PRIMARY KEY (user_id, credit_no) + ); + + CREATE TABLE login_hist_t ( + user_id VARCHAR(10), + sfx INT, + login_datetime DATETIME, + conn_ip VARCHAR(20), + term_info VARCHAR(20), + PRIMARY KEY (user_id, sfx) + ); + + +--ƒŒƒR�[ƒh +--ŒÚ‹qƒ}ƒXƒ^ + INSERT INTO user_m VALUES ( + 'CU00000001','ŽR“c','ƒ„ƒ}ƒ_','ˆê','ƒnƒWƒ�', + '1973-06-06','J0','h.yamada@hoge.com', + '140-0014','“Œ‹ž“s','•i�ì‹æ','‘åˆä', + '�›�›-�›','ƒ}ƒ“ƒVƒ‡ƒ“1399','090-xxxx-xxxx','hX8UEE3' + ); + + INSERT INTO user_m VALUES ( + 'CU00000002','�‚‹´','ƒ^ƒJƒnƒV','—´–ç','ƒ^ƒcƒ„', + '1970-11-10','J0','t.takahashi@hoge.com', + '230-0063','�_“Þ�쌧','‰¡•lŽs’ߌ©‹æ','’ߌ©', + '�~�[�~�~','', '090-xxxx-xxxx','UQ0A6B3R' + ); + + INSERT INTO user_m VALUES ( + 'CU00000003','�•Ž}','ƒ}ƒGƒ_','�y','ƒWƒ…ƒ“', + '1975-01-03','J0','j.maeda@hoge.com', + '333-0823','�é‹ÊŒ§','�ìŒûŽs','�Î�_', + '�›�›-�›','','090-yyyy-1234','DUHwNLLk' + ); + + INSERT INTO user_m VALUES ( + 'CU00000004','“ñ‘î','ƒ~ƒ„ƒP','�͉î','ƒVƒ‡ƒEƒXƒP', + '1970-10-10','J0','s.miyake@hoge.com', + '273-0031','�ç—tŒ§','‘D‹´Žs','�¼‘D', + '�›�›-�›','ƒAƒp�[ƒg101','090-yyyy-5678','F2QG7Nzw' + ); + + INSERT INTO user_m VALUES ( + 'CU00000005','—ÁŒ³','ƒXƒYƒ‚ƒg','—Iˆê','ƒ†ƒEƒCƒ`', + '1969-01-13','J0','y.suzumoto@hoge.com', + '321-0207','“È–ØŒ§','‰º“s‰êŒS�p�¶’¬','–k�¬—Ñ', + '�~�~�~�~','','090-1234-xxxx','DZy5qadL' + ); + +--ƒNƒŒƒWƒbƒgƒJ�[ƒh + INSERT INTO credit_card_t VALUES ( + 'CU00000001', + 'CD001', + 'xxxx-xxxx-xxxx-xxxx', + 'HAJIME YAMADA', + '03', + 2017, + 'xxx' + ); + + INSERT INTO credit_card_t VALUES ( + 'CU00000005', + 'CD001', + 'xxxx-xxxx-xxxx-xxxx', + 'YUICHI SUZUMOTO', + '03', + 2016, + 'xxx' + ); + +--ƒ�ƒOƒCƒ“�î•ñ + INSERT INTO login_hist_t VALUES ( + 'CU00000001',1, + '2014-10-01 10:00:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000001',2, + '2014-10-10 12:27:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000001',3, + '2014-10-25 20:30:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000001',4, + '2014-11-03 10:15:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000001',5, + '2014-11-05 15:06:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000001',6, + '2014-12-01 16:56:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000002',1, + '2014-05-05 15:30:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000002',2, + '2014-07-07 12:30:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000002',3, + '2014-11-25 09:30:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000003',1, + '2013-12-24 11:11:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000003',2, + '2014-01-10 12:20:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000003',3, + '2014-10-10 15:27:00', + 'xxx.xxx.xxx.xxx', + 'PC' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000004',1, + '2014-07-10 00:00:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + INSERT INTO login_hist_t VALUES ( + 'CU00000005',1, + '2014-07-05 19:42:00', + 'xxx.xxx.xxx.xxx', + 'ƒXƒ}�[ƒgƒtƒHƒ“' + ); + + + diff --git a/ç·´ç¿’å•�題/Part3.1.3.sql b/ç·´ç¿’å•�題/Part3.1.3.sql new file mode 100644 index 0000000..7b96253 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.3.sql @@ -0,0 +1,63 @@ +--�¤•iƒ}ƒXƒ^ + CREATE TABLE goods_m ( + goods_id VARCHAR(10) PRIMARY KEY, + goods_nm VARCHAR(100), + goods_maker VARCHAR(50), + goods_div_cd VARCHAR(5), + handling_date DATE, + goods_price INT, + goods_cost INT + ); + +--ƒŒƒR�[ƒh + INSERT INTO goods_m VALUES ( + 'ITM0000001', + 'EIZO FlexScan 27ƒCƒ“ƒ`ƒJƒ‰�[‰t�»ƒ‚ƒjƒ^�[', + 'EIZO', + 'K0002', + '2012-08-24', + 79110, + 40000 + ); + + INSERT INTO goods_m VALUES ( + 'ITM0000002', + 'ƒTƒbƒJ�[ “ú–{‘ã•\ ”Ô�†‚ ‚背ƒvƒŠƒJƒ†ƒjƒtƒH�[ƒ€', + 'adidas', + 'K0003', + '2014-03-04', + 12915, + 2000 + ); + + INSERT INTO goods_m VALUES ( + 'ITM0000003', + 'ƒŒƒCƒ“ƒEƒFƒA‚Ó‚Æ‚ñƒNƒŠ�[ƒi�[�iƒp�[ƒ‹ƒzƒ�ƒCƒg�j', + 'ƒŒƒCƒ“ƒEƒFƒA', + 'K0006', + '2013-09-17', + 24500, + 12000 + ); + + INSERT INTO goods_m VALUES ( + 'ITM0000004', + 'ƒvƒŒƒKƒŠƒAƒAƒbƒvƒv�[ƒ‹ƒIƒXƒ}ƒ“ EDT SP 100ml', + 'ƒvƒŒƒKƒŠƒA', + 'K0007', + '2010-03-03', + 3712, + 1500 + ); + + INSERT INTO goods_m VALUES ( + 'ITM0000005', + 'ƒ}ƒWƒbƒN�EƒU�EƒMƒƒƒUƒŠƒ“ƒO Šî–{ƒZƒbƒg2015 ƒu�[ƒXƒ^�[ƒpƒbƒN “ú–{Œê”Å BOX', + 'ƒEƒBƒU�[ƒY�EƒIƒu�EƒU�EƒR�[ƒXƒg', + 'K0008', + '2014-04-28', + 10952, + 6000 + ); + + diff --git a/ç·´ç¿’å•�題/Part3.1.4.sql b/ç·´ç¿’å•�題/Part3.1.4.sql new file mode 100644 index 0000000..dc0e6a9 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.4.sql @@ -0,0 +1,24 @@ +--‘qŒÉƒ}ƒXƒ^ + CREATE TABLE store_m ( + store_id VARCHAR(5) PRIMARY KEY, + store_nm VARCHAR(50), + store_post_no VARCHAR(8), + store_prefecture_nm VARCHAR(20), + store_municipality_nm VARCHAR(50), + store_city_nm VARCHAR(50), + store_address VARCHAR(100), + store_building_nm VARCHAR(100) + ); + +--ƒŒƒR�[ƒh + INSERT INTO store_m VALUES ( + 'W0001', + '‘åˆä‘qŒÉ', + '140-0014', + '“Œ‹ž“s', + '•i�ì‹æ', + '‘åˆä', + 'XXXXXXXXXXXXXXX', + 'XXXXXXXX' + ); + diff --git a/ç·´ç¿’å•�題/Part3.1.5.sql b/ç·´ç¿’å•�題/Part3.1.5.sql new file mode 100644 index 0000000..b5a6c72 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.5.sql @@ -0,0 +1,27 @@ +--�݌Ƀ}ƒXƒ^ + CREATE TABLE stock_m ( + stock_id VARCHAR(5), + goods_id VARCHAR(10), + arrival_date DATE, + arrival_num INT, + security_num INT, + PRIMARY KEY (stock_id, goods_id, arrival_date) + ); + +--ƒŒƒR�[ƒh + INSERT INTO stock_m VALUES + ('W0001','ITM0000001','2012-08-24',2,2), + ('W0001','ITM0000001','2012-12-25',3,3), + ('W0001','ITM0000001','2013-06-01',2,2), + ('W0001','ITM0000001','2013-11-20',5,4), + ('W0001','ITM0000001','2014-08-06',7,0), + ('W0001','ITM0000002','2014-03-04',100,100), + ('W0001','ITM0000002','2014-09-05',50,45), + ('W0001','ITM0000002','2014-09-10',60,0), + ('W0001','ITM0000003','2013-09-17',5,2), + ('W0001','ITM0000004','2010-03-03',10,10), + ('W0001','ITM0000004','2012-10-05',3,3), + ('W0001','ITM0000004','2013-09-10',6,5), + ('W0001','ITM0000004','2014-04-03',2,0), + ('W0001','ITM0000005','2014-04-28',150,150), + ('W0001','ITM0000005','2014-05-20',100,86); diff --git a/ç·´ç¿’å•�題/Part3.1.6.sql b/ç·´ç¿’å•�題/Part3.1.6.sql new file mode 100644 index 0000000..14e66e2 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.6.sql @@ -0,0 +1,36 @@ +--“üŒÉƒe�[ƒuƒ‹ + CREATE TABLE ins_stock_m ( + goods_id VARCHAR(10), + store_id VARCHAR(5), + ins_stock_exp_date DATE, + ins_stock_cmp_date DATE, + ins_stock_exp_num INT, + ins_stock_num INT, + PRIMARY KEY (goods_id, store_id, ins_stock_exp_date) + ); + +--ƒŒƒR�[ƒh + INSERT INTO ins_stock_m VALUES + ('ITM0000004','W0001','2010-03-03','2010-03-03',10,10), + ('ITM0000001','W0001','2012-08-24','2012-08-24',2,2), + ('ITM0000004','W0001','2012-10-05','2012-10-05',3,3), + ('ITM0000001','W0001','2012-12-25','2012-12-25',3,3), + ('ITM0000001','W0001','2013-06-01','2013-06-01',2,2), + ('ITM0000004','W0001','2013-09-10','2013-09-10',6,6), + ('ITM0000003','W0001','2013-09-17','2013-09-17',5,5), + ('ITM0000001','W0001','2013-11-20','2013-11-20',5,5), + ('ITM0000002','W0001','2014-03-04','2014-03-04',100,100), + ('ITM0000004','W0001','2014-04-03','2014-04-03',2,2), + ('ITM0000005','W0001','2014-04-28','2014-04-28',150,150), + ('ITM0000005','W0001','2014-05-20','2014-05-20',100,100), + ('ITM0000001','W0001','2014-08-08','2014-08-08',7,7), + ('ITM0000002','W0001','2014-09-05','2014-09-05',50,50), + ('ITM0000002','W0001','2014-09-10','2014-09-10',60,60), + ('ITM0000001','W0001','2014-12-03',NULL,5,NULL), + ('ITM0000002','W0001','2014-12-10',NULL,200,NULL), + ('ITM0000003','W0001','2014-12-12',NULL,3,NULL), + ('ITM0000004','W0001','2014-12-15',NULL,10,NULL), + ('ITM0000005','W0001','2014-12-25',NULL,80,NULL) + SELECT * FROM ins_stock_m + ORDER BY ins_stock_exp_date; + diff --git a/ç·´ç¿’å•�題/Part3.1.7.sql b/ç·´ç¿’å•�題/Part3.1.7.sql new file mode 100644 index 0000000..057ca26 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.1.7.sql @@ -0,0 +1,57 @@ +--’�•¶ + CREATE TABLE order_t ( + order_no INT PRIMARY KEY, + order_date DATE, + user_id VARCHAR(10), + sts_cd VARCHAR(10), + pay_div_cd VARCHAR(10), + deli_exp_date DATE, + deli_date DATE, + deli_company VARCHAR(20), + tracing_no VARCHAR(20), + arrive_exp_date DATE, + deli_comm INT, + postage INT, + tax_rate INT + ); + + CREATE TABLE order_detail_t ( + order_no INT, + goods_id VARCHAR(10), + goods_unit_price INT, + goods_num INT, + PRIMARY KEY (order_no, goods_id) + ); + +--ƒŒƒR�[ƒh + INSERT INTO order_t VALUES + (1,'2014-11-20','CU00000003','ST010','PY002', + '2014-11-20','2014-11-20','ƒ„ƒ}ƒg','xxxxxxxxxx', + '2014-11-21',0,1836,20850), + (2,'2014-11-25','CU00000001','ST010','PY001', + '2014-11-25','2014-11-25','ƒ„ƒ}ƒg','xxxxxxxxxx', + '2014-11-26',0,1836,94520), + (3,'2014-11-30','CU00000005','ST010','PY001', + '2014-12-02','2014-12-02','ƒ„ƒ}ƒg','xxxxxxxxxx', + '2014-12-03',0,1836,108562), + (4,'2014-12-02','CU00000004','ST010','PY004', + '2014-12-02','2014-12-02','ƒ„ƒ}ƒg','xxxxxxxxxx', + '2014-12-03',510,1836,103310); + + INSERT INTO order_detail_t VALUES + (1,'ITM0000002',12915,100), + (1,'ITM0000005',10952,80), + (1,'ITM0000003',24500,1), + (1,'ITM0000004',3712,5), + (1,'ITM0000001',79110,5), + (2,'ITM0000001',79110,1), + (2,'ITM0000002',12915,50), + (2,'ITM0000004',3712,5), + (2,'ITM0000005',10952,40), + (3,'ITM0000001',79110,3), + (3,'ITM0000003',24500,1), + (3,'ITM0000005',10952,100), + (4,'ITM0000001',79110,2), + (4,'ITM0000002',12915,60), + (4,'ITM0000004',3712,8), + (4,'ITM0000005',10952,30); diff --git a/ç·´ç¿’å•�題/Part3.2.sql b/ç·´ç¿’å•�題/Part3.2.sql new file mode 100644 index 0000000..b5b5487 --- /dev/null +++ b/ç·´ç¿’å•�題/Part3.2.sql @@ -0,0 +1,53 @@ +--2.1 + CREATE VIEW goods_stock_v AS + SELECT + goods_m.goods_id, + goods_m.goods_nm, + SUM(stock_m.arrival_num - stock_m.security_num) AS stock_num + FROM goods_m + INNER JOIN stock_m + ON goods_m.goods_id = stock_m.goods_id + GROUP BY + goods_m.goods_id, + goods_m.goods_nm; + + CREATE VIEW user_credit_v AS + SELECT + user_m.user_id, + user_m.user_f_nm, + user_m.user_nm, + gender_m.gender_div_nm, + user_m.mail_address, + credit_card_t.credit_div_cd, + credit_card_t.credit_no, + credit_card_t.credit_nm + FROM user_m + LEFT JOIN credit_card_t + ON user_m.user_id = credit_card_t.user_id + LEFT JOIN gender_m + ON user_m.gender_cd = gender_m.gender_cd; + + CREATE VIEW ins_stock_schedule_v AS + SELECT + ins_stock_m.goods_id, + goods_m.goods_nm, + ins_stock_m.ins_stock_exp_date, + ins_stock_m.store_id, + store_m.store_nm + FROM ins_stock_m + INNER JOIN goods_m + ON ins_stock_m.goods_id = goods_m.goods_id + INNER JOIN store_m + ON ins_stock_m.store_id = store_m.store_id + WHERE ins_stock_m.ins_stock_cmp_date IS NULL; + + +--2.2 + + CREATE SEQUENCE order_no_seq + START WITH 5 + INCREMENT BY 1; + + + + diff --git a/ç·´ç¿’å•�題/サンプル.sql b/ç·´ç¿’å•�題/サンプル.sql new file mode 100644 index 0000000..fb213cd --- /dev/null +++ b/ç·´ç¿’å•�題/サンプル.sql @@ -0,0 +1,21 @@ +CREATE TABLE emp_table ( + emp_no INT, + emp_name VARCHAR(50), + salary INT +); + +--“o˜^ +INSERT INTO emp_table VALUES(1, 'ˆä�ã', 20000); +INSERT INTO emp_table VALUES(2, '“c’†', 50000); + +-- ŒŸ�õ +SELECT * FROM emp_table; +SELECT * FROM emp_table; WHERE emp_no = 1; + +--�X�V +UPDATE emp_table SET salary = 100; +SELECT * FROM emp_table; + +--�í�œ +DELETE FROM emp_table; +SELECT * FROM emp_table;