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

[Round3] 객체와 클래스, 객체지향 프로그래밍, sql로 하는 데이터 분석 실습 #35

Open
wants to merge 2 commits 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE customer_order (
id INT NOT NULL AUTO_INCREMENT,
item_no INT NOT NULL,
payment_id INT NOT NULL,
approval_time DATETIME NOT NULL,
PRIMARY KEY(id));

CREATE TABLE delivery (
id INT NOT NULL AUTO_INCREMENT,
order_id INT NULL,
location_code TINYINT NOT NULL,
status_code TINYINT NOT NULL,
recent_update_time DATETIME NOT NULL,
PRIMARY KEY(id));

INSERT INTO customer_order VALUES (10000, 102, 1304, '2020-06-02 17:42:29');
INSERT INTO customer_order VALUES (10001, 304, 1305, '2020-06-02 17;50:04');
INSERT INTO customer_order VALUES (10002, 2091, 1306, '2020-06-02 18:00:51');


INSERT INTO delivery VALUES (9983, 10000, 1, 0, '2020-06-03 18:00:23');
INSERT INTO delivery VALUES (9984, 10001, 3, 1, '2020-06-04 15:23:27');
INSERT INTO delivery VALUES (9985, 10002, 4, 2, '2020-06-05 09:12:03');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 여기에 코드를 작성하세요
ALTER TABLE delivery
ADD CONSTRAINT fk_delivery_order
FOREIGN KEY delivery(order_id)
REFERENCES customer_order(id)
ON DELETE SET null
ON UPDATE CASCADE;


# 테스트 코드
DELETE FROM customer_order WHERE id = 10000;
UPDATE customer_order SET id = 21000 WHERE id = 10001;

SELECT * FROM delivery;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE TABLE beta_review(
id INT NOT NULL AUTO_INCREMENT,
email VARCHAR(40) NOT NULL,
age INT NOT NULL,
comment VARCHAR(80) NOT NULL,
PRIMARY KEY(id)
);



INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 27 , '앱 디자인이 간단해서 보기가 좋네요.');
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 30 , '왜 제 폰에서는 실행되자마자 꺼질까요 ㅜㅜ' );
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 40 , '애니메이션이 너무 이뻐요 ^^! 쇼핑하고픈 욕구가 마구 생겨요~' );
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 42 , '주문 창이 너무 늦게 뜨는 것 같아요, 해결해주세요');
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 35 , '오 이 앱 나오면 앞으로 여기꺼만 써야지~' );
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 46 , '간혹 버벅거릴 때가 있는 것 빼고는 쓸만한 듯');
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 25 , '물품 분류가 좀더 세분화되면 좋을 것 같네요' );
INSERT INTO beta_review (email, age, comment) VALUES ( '[email protected]' , 19 , '이거 필터 아이콘 UI가 너무 이쁘네요 ㅋㅋ, 디자이너 짱');
INSERT INTO beta_review (email, age, comment) VALUES ( 'gotCHAgood!#@navez.com' , 27 , '흠.. 왜 내 껀 켜자마자 꺼져버리지');
INSERT INTO beta_review (email, age, comment) VALUES ( 'orilly@[email protected]' , 33 , '사용성 엄청 좋네.. 역시 코팡, 정식 출시되면 믿고 쇼핑하겠습니다~!' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 여기에 코드를 작성하세요
CREATE TABLE beta_review_20s LIKE beta_review;
INSERT INTO beta_review_20s SELECT * FROM beta_review WHERE age>=20 AND age <30;

# 테스트 코드
SELECT * FROM beta_review_20s;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE item (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
type VARCHAR(20) NOT NULL,
price INT NOT NULL,
description VARCHAR(200) NOT NULL,
upload_date DATE NOT NULL,
purchased CHAR(1) NOT NULL,
is_deleted CHAR(1) NOT NULL,
PRIMARY KEY(id));

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('신생아 모자', '의류', 20000, '굵은 망사형 제품으로..', '2019-03-23', 'N', 'Y');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('아이팻 프로', '전자기기', 300000, '작동하는데는 큰 문제 없어요, 대신..', '2020-01-05', 'Y', 'Y');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('남성정장 상하의 세트', '의류', 100000, '제가 보통 상의가 100이고, 하의를..', '2018-07-03', 'N', 'N');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('나무로 된 수납장', '가구/인테리어', 50000, '꽤 좋은 원목으로 만들어진..', '2020-05-23', 'Y', 'N');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('Java 관련 책들', '도서', 50000, '자바 공부 엄청 열심히 한 시절에..', '2020-04-17', 'N', 'Y');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('대학생용 백팩', '악세서리', 800000, '명품 브랜드 XXX 거에요, 진짜 아끼는 건데..', '2017-02-05', 'Y', 'Y');

INSERT INTO item (name, type, price, description, upload_date, purchased, is_deleted) VALUES ('나이끼 조던 한정판', '의류', 1200000, '선물로 같은 종류의 한정판 신발을..', '2018-10-06', 'N', 'Y');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 여기에 코드를 작성하세요
UPDATE item SET is_deleted = 'Y' WHERE id = 3;
DELETE FROM item WHERE is_deleted ='Y' AND DATEDIFF('2020-07-05', upload_date)>365;




# 테스트 코드
SELECT * FROM item;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE food_menu(
id INT NOT NULL AUTO_INCREMENT,
menu VARCHAR(10) NOT NULL,
price INT NOT NULL,
ingredient VARCHAR(150) NOT NULL,
PRIMARY KEY(id));
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 여기에 코드를 작성하세요
INSERT INTO food_menu (menu, price, ingredient) VALUES('라볶이', 5000, '라면, 떡, 양파..');
INSERT INTO food_menu (menu, price, ingredient) VALUES('치즈김밥', 3000, '치즈, 김, 단무지..');
INSERT INTO food_menu (menu, price, ingredient) VALUES('돈까스', 8000, '국내산 돼지고기, 양배추..');
INSERT INTO food_menu (menu, price, ingredient) VALUES('오므라이스', 7000, '계란, 당근..');


# 테스트 코드
SELECT * FROM food_menu;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 여기에 코드를 작성하세요
CREATE TABLE animal_info
(
id INT AUTO_INCREMENT PRIMARY KEY,
type VARCHAR(30),
name VARCHAR(10),
age TINYINT,
sex CHAR(1),
weight DOUBLE,
feature VARCHAR(500),
entry_date DATE
);



/* 테이블이 생성된 후에 아래의
INSERT문들이 실행되면서 3개의 로우가 추가됩니다 */

INSERT INTO animal_info (type, name, age, sex, weight, feature, entry_date) VALUES ('사자', '리오', 8, 'm', 170.5, '상당히 날렵하고 성격이 유순한 편임', '2015-03-21');
INSERT INTO animal_info (type, name, age, sex, weight, feature, entry_date) VALUES ('코끼리', '조이', 15, 'f', 3000, '새끼 때 무리에서 떨어져 길을 잃고 방황하다가 동물원에 들어와서 적응을 잘 마침', '2007-07-16');
INSERT INTO animal_info (type, name, age, sex, weight, feature, entry_date) VALUES ('치타', '매튜', 20, 'm', 62, '나이가 노령이라 최근 활동량이 현저히 줄어든 모습이 보임', '2003-11-20');

# 테스트 코드
SELECT * FROM animal_info;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE shoes (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(10) NOT NULL,
size INT NOT NULL,
brand VARCHAR(20) NULL,
PRIMARY KEY(id)
);

INSERT INTO shoes (name, size, brand) VALUES ('MK-120', 260, 'Nice');
INSERT INTO shoes (name, size, brand) VALUES ('AOS-347', 270, 'Akidas');
INSERT INTO shoes (name, size, brand) VALUES ('ZMQ-83', 260, 'Heebok');
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 여기에 코드를 작성하세요
ALTER TABLE shoes RENAME COLUMN name TO model;
ALTER TABLE shoes MODIFY size DOUBLE NOT NULL;
ALTER TABLE shoes DROP COLUMN brand;
ALTER TABLE shoes ADD stock INT NOT NULL;



# 테스트 코드
DESCRIBE shoes;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_6687b97a8d08d173c2c9c490`;
CREATE DATABASE `db_6687b97a8d08d173c2c9c490` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_6687b97a8d08d173c2c9c490'@'%';
CREATE USER 'user_6687b97a8d08d173c2c9c490'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_6687b97a8d08d173c2c9c490`.* TO 'user_6687b97a8d08d173c2c9c490'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE book (
id INT NOT NULL AUTO_INCREMENT,
isbn VARCHAR(50) NULL,
page INT NOT NULL,
author VARCHAR(20) NOT NULL,
kind VARCHAR(10) NOT NULL,
location VARCHAR(10) NOT NULL,
PRIMARY KEY(id));


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 여기에 코드를 작성하세요
ALTER TABLE book
MODIFY isbn VARCHAR(50) NOT NULL UNIQUE,
ADD CONSTRAINT page_rule CHECK (page>0),
CHANGE kind genre_code INT NOT NULL,
MODIFY location VARCHAR(10) NOT NULL DEFAULT 'warehouse';

# 테스트 코드
DESC book;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE pizza_price_cost (id INTEGER PRIMARY KEY, name TEXT, price INTEGER, cost INTEGER);
INSERT INTO pizza_price_cost VALUES (1, 'Potato Bacon Pizza', 22000, 14000);
INSERT INTO pizza_price_cost VALUES (2, 'Sweet Potato Pizza', 24000, 14000);
INSERT INTO pizza_price_cost VALUES (3, 'Combination Pizza', 25000, 13000);
INSERT INTO pizza_price_cost VALUES (4, 'Bacon Cheddar Pizza', 32000, 20000);
INSERT INTO pizza_price_cost VALUES (5, 'Pineapple Pizza', 25000, 22000);
INSERT INTO pizza_price_cost VALUES (6, 'Garlic Shrimp Pizza', 26000, 19000);
INSERT INTO pizza_price_cost VALUES (7, 'Cheeze Pizza', 23000, 17000);
INSERT INTO pizza_price_cost VALUES (8, 'Pepperoni Pizza', 24000, 13000);

CREATE TABLE sales (id INTEGER PRIMARY KEY, menu_id INTEGER, sales_volume INTEGER);
INSERT INTO sales VALUES (1, 2, 220);
INSERT INTO sales VALUES (2, 3, 137);
INSERT INTO sales VALUES (3, 5, 121);
INSERT INTO sales VALUES (4, 6, 225);
INSERT INTO sales VALUES (5, 8, 167);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT p.name , COALESCE(s.sales_volume, '판매량 정보 없음') AS '판매량'
FROM pizza_price_cost AS p LEFT OUTER JOIN sales AS s ON p.id = s.menu_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE 2020_movie_report (id INTEGER PRIMARY KEY, name TEXT, category TEXT, main_month INTEGER, view_count INTEGER);
INSERT INTO 2020_movie_report
VALUES (1,'태극권 배우기', 'Action', 3, 120000),
(2, '여름 왕국', 'Fantasy', 6, 10000000),
(3, '성태후 일병 구하기', 'Drama', 5, 5000000),
(4, '그날 너를 보았다', 'Romance', 4, 7000000),
(5, '다이이지', 'Action', 5, 2300000),
(6, '쓰리캅스', 'Action', 5, 7000000),
(7, '매드미니멈', 'Action', 4, 8500000),
(8, '무인도, 20일', 'Thriller', 4, 1000000),
(9, '허씨표류기', 'Comedy', 5, 300000),
(10, '링거전쟁', 'Thriller', 3, 150000),
(11, '타임백투유', 'Romance', 3, 5000000),
(12, '그렇게 살아간다', 'Drama', 3, 3200000),
(13, '배틀스타', 'SF', 4, 1650000),
(14, '내일은 결혼식', 'Comedy', 5, 2000000),
(15, '화성탈출', 'SF', 5, 4500000);





Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT category, main_month, COUNT(*) AS "영화 수", SUM(view_count) AS "총 관객 수"
FROM 2020_movie_report
GROUP BY category, main_month
HAVING main_month = 5 AND SUM(view_count) >= 3000000;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE review (id INTEGER PRIMARY KEY, star INTEGER, comment TEXT, registration_date DATE);
INSERT INTO review VALUES (1, 2, NULL, '2020-01-02');
INSERT INTO review VALUES (2, 5, '페페로니의 향을 빠르게 맛볼 수 있었어요', '2020-03-24');
INSERT INTO review VALUES (3, 3, '맛은 있는데, 배달이 너무 느렸어요', '2020-04-21');
INSERT INTO review VALUES (4, NULL, NULL, '2019-11-23');
INSERT INTO review VALUES (5, 3, '사진이랑 조금 다르지만 먹을만 하네', '2019-09-14');
INSERT INTO review VALUES (6, 5, NULL, '2020-05-02');
INSERT INTO review VALUES (7, 2, '왜 피클을 안 넣어주셨죠?', '2019-10-05');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT COUNT(*), ROUND(AVG(star))
FROM review
WHERE comment IS NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE review (id INTEGER PRIMARY KEY, star INTEGER, comment TEXT, registration_date DATE);
INSERT INTO review VALUES (1, 2, '치즈가 좀 부족해요', '2020-01-02');
INSERT INTO review VALUES (2, 5, '페페로니의 향을 빠르게 맛볼 수 있었어요', '2020-03-24');
INSERT INTO review VALUES (3, 3, '맛은 있는데, 배달이 너무 느렸어요', '2020-04-21');
INSERT INTO review VALUES (4, 2, '너무 비싸요, 세일은 안 하나요?', '2019-11-23');
INSERT INTO review VALUES (5, 3, '사진이랑 조금 다르지만 먹을만 하네', '2019-09-14');
INSERT INTO review VALUES (6, 5, '최고의 맛, 어느새 단골이 되었네요^^', '2020-05-02');
INSERT INTO review VALUES (7, 2, '왜 피클을 안 넣어주셨죠?', '2019-10-05');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT * FROM review ORDER BY star ASC , registration_date DESC LIMIT 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE member (id INTEGER PRIMARY KEY, email TEXT, age INTEGER, sign_up_day DATE);
INSERT INTO member VALUES (1, '[email protected]', 32, '2019-07-23');
INSERT INTO member VALUES (2, '[email protected]', 21, '2015-03-24');
INSERT INTO member VALUES (3, '[email protected]', 24, '2018-07-11');
INSERT INTO member VALUES (4, '[email protected]', 27, '2018-12-20');
INSERT INTO member VALUES (5, '[email protected]', 24, '2019-06-27');
INSERT INTO member VALUES (6, '[email protected]', 23, '2016-07-01');
INSERT INTO member VALUES (7, '[email protected]', 26, '2017-12-20');
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT * FROM member WHERE age BETWEEN 20 AND 30
AND MONTH(sign_up_day) = 7 ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP DATABASE IF EXISTS `db_668174285a66b96b32ccf341`;
CREATE DATABASE `db_668174285a66b96b32ccf341` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
DROP USER IF EXISTS 'user_668174285a66b96b32ccf341'@'%';
CREATE USER 'user_668174285a66b96b32ccf341'@'%';
GRANT SELECT, UPDATE, DELETE, INSERT, CREATE, DROP, CREATE VIEW, ALTER, REFERENCES ON `db_668174285a66b96b32ccf341`.* TO 'user_668174285a66b96b32ccf341'@'%';
FLUSH PRIVILEGES;
Loading