This commit is contained in:
2026-10-28 10:48:39 +09:00
parent 1becaf2b81
commit 8c328ae16e
5 changed files with 130 additions and 1 deletions

View File

@@ -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