Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taehyun (20231112): SQL 레벨업 3-4장 #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file removed Document/2023/1022/haneul/.gitkeep
Empty file.
Empty file.
Empty file.
Empty file removed Document/2023/1022/siyeon/.gitkeep
Empty file.
Empty file.
Empty file removed Document/2023/1022/yubin/.gitkeep
Empty file.
8 changes: 8 additions & 0 deletions Document/2023/1112/taehyun/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mysql:5.7

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_DATABASE=test_group_by

COPY ./query.sql /docker-entrypoint-initdb.d/

CMD ["--max_allowed-packet=32505856"]
414 changes: 414 additions & 0 deletions Document/2023/1112/taehyun/README.md

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions Document/2023/1112/taehyun/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE DATABASE IF NOT EXISTS test_group_by DEFAULT CHARACTER SET utf8mb4;

USE test_group_by;

CREATE TABLE IF NOT EXISTS Items1 (
item_id INTEGER NOT NULL,
year INTEGER NOT NULL,
item_name VARCHAR(255) NOT NULL,
price INTEGER NOT NULL,

PRIMARY KEY (item_id, year)
);

CREATE TABLE IF NOT EXISTS Items2 (
item_id INTEGER NOT NULL,
year INTEGER NOT NULL,
item_name VARCHAR(255) NOT NULL,
price INTEGER NOT NULL,

PRIMARY KEY (year, item_id)
);

DELIMITER $$
CREATE PROCEDURE CreateItem(IN fixed_item_id INT, IN fixed_item_name VARCHAR(255))
BEGIN
DECLARE current_year INT DEFAULT 1;
DECLARE current_price INT DEFAULT 10;

WHILE current_year <= 1000000 DO
INSERT INTO Items1 (item_id, year, item_name, price) VALUES (fixed_item_id, current_year, fixed_item_name, current_price);
SET current_year = current_year + 1;
SET current_price = current_price + 10;
END WHILE;
END $$
DELIMITER ;

CALL CreateItem(101, '머그컵');
CALL CreateItem(102, '티스푼');
CALL CreateItem(103, '나이프');

INSERT INTO Items2 (item_id, year, item_name, price)
SELECT item_id, year, item_name, price FROM Items1;