From c8a0816f9b7efb5915f1801054a244b3d2167a93 Mon Sep 17 00:00:00 2001 From: gwanghui97 Date: Thu, 16 May 2024 17:03:26 +0900 Subject: [PATCH 1/6] edit Part1.java --- .idea/.gitignore | 3 +++ .idea/compiler.xml | 6 ++++++ .idea/gradle.xml | 15 +++++++++++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/misc.xml | 5 +++++ .idea/vcs.xml | 6 ++++++ src/main/java/com/jungmin/script/Part1.java | 2 +- 7 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..f9163b4 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f50fada --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/com/jungmin/script/Part1.java b/src/main/java/com/jungmin/script/Part1.java index 868c8cd..81784b3 100644 --- a/src/main/java/com/jungmin/script/Part1.java +++ b/src/main/java/com/jungmin/script/Part1.java @@ -17,7 +17,7 @@ public class Part1 { TODO: Q 1-2. Users 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Users 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_2 = "DESCRIBE Users;"; + public static final String PART1_2 = "DESC Users;"; /* ---------------------------------------------------------------------------------------------- From 32292c6c42e932439a7154a4e89251a34ff9d58e Mon Sep 17 00:00:00 2001 From: gwanghui97 Date: Thu, 16 May 2024 17:22:22 +0900 Subject: [PATCH 2/6] DS_store removed --- .gitignore | 1 + .gradle/7.4/checksums/checksums.lock | Bin 0 -> 17 bytes .../dependencies-accessors.lock | Bin 0 -> 17 bytes .gradle/7.4/dependencies-accessors/gc.properties | 0 .gradle/7.4/executionHistory/executionHistory.lock | Bin 0 -> 17 bytes .gradle/7.4/fileChanges/last-build.bin | Bin 0 -> 1 bytes .gradle/7.4/fileHashes/fileHashes.lock | Bin 0 -> 17 bytes .gradle/7.4/gc.properties | 0 .gradle/buildOutputCleanup/buildOutputCleanup.lock | Bin 0 -> 17 bytes .gradle/buildOutputCleanup/cache.properties | 2 ++ .gradle/vcs-1/gc.properties | 0 11 files changed, 3 insertions(+) create mode 100644 .gitignore create mode 100644 .gradle/7.4/checksums/checksums.lock create mode 100644 .gradle/7.4/dependencies-accessors/dependencies-accessors.lock create mode 100644 .gradle/7.4/dependencies-accessors/gc.properties create mode 100644 .gradle/7.4/executionHistory/executionHistory.lock create mode 100644 .gradle/7.4/fileChanges/last-build.bin create mode 100644 .gradle/7.4/fileHashes/fileHashes.lock create mode 100644 .gradle/7.4/gc.properties create mode 100644 .gradle/buildOutputCleanup/buildOutputCleanup.lock create mode 100644 .gradle/buildOutputCleanup/cache.properties create mode 100644 .gradle/vcs-1/gc.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/.gradle/7.4/checksums/checksums.lock b/.gradle/7.4/checksums/checksums.lock new file mode 100644 index 0000000000000000000000000000000000000000..572ab1320674de1daa200f1052b78dd327168075 GIT binary patch literal 17 TcmZQBy}qLN-hN(N1}FdkIm!fV literal 0 HcmV?d00001 diff --git a/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000000000000000000000000000000000000..6b6ef6b4b8388b1243f8639f127a8d6ee70341c1 GIT binary patch literal 17 ScmZQRH>JqDJt~) literal 0 HcmV?d00001 diff --git a/.gradle/7.4/dependencies-accessors/gc.properties b/.gradle/7.4/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/7.4/executionHistory/executionHistory.lock b/.gradle/7.4/executionHistory/executionHistory.lock new file mode 100644 index 0000000000000000000000000000000000000000..4632ab39e552d6ab574e15dbe4bbce6ced4a5793 GIT binary patch literal 17 TcmZRU Date: Thu, 16 May 2024 17:20:30 +0900 Subject: [PATCH 3/6] Update Part1.java --- src/main/java/com/jungmin/script/Part1.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/jungmin/script/Part1.java b/src/main/java/com/jungmin/script/Part1.java index 81784b3..84c6b55 100644 --- a/src/main/java/com/jungmin/script/Part1.java +++ b/src/main/java/com/jungmin/script/Part1.java @@ -24,34 +24,34 @@ public class Part1 { TODO: Q 1-3. Posts 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Posts 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_3 = "desc posts"; + public static final String PART1_3 = "DESCRIBE posts"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-4. Tags 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Tags 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_4 = "desc Tags"; + public static final String PART1_4 = "DESCRIBE Tags"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-5. Post_Tags 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Post_Tags 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_5 = "desc Post_Tags"; + public static final String PART1_5 = "DESCRIBE Post_Tags"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-6. Comments 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Comments 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_6 = "desc Comments"; + public static final String PART1_6 = "DESCRIBE Comments"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-7. Boards 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Boards 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_7 = "desc Boards"; + public static final String PART1_7 = "DESCRIBE Boards"; } From 1f8259fcec16829c0d5e29dfb7bc78f8f92bf8ac Mon Sep 17 00:00:00 2001 From: gwanghui97 Date: Thu, 16 May 2024 18:06:22 +0900 Subject: [PATCH 4/6] Submit assignment --- .../java/com/jungmin/migrations/schema.sql | 74 ++++++++++--------- src/main/java/com/jungmin/script/Part1.java | 16 ++-- src/main/java/com/jungmin/script/Part2.java | 43 ++++++----- 3 files changed, 70 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/jungmin/migrations/schema.sql b/src/main/java/com/jungmin/migrations/schema.sql index 1136c54..c1c2a4c 100644 --- a/src/main/java/com/jungmin/migrations/schema.sql +++ b/src/main/java/com/jungmin/migrations/schema.sql @@ -1,46 +1,48 @@ -CREATE TABLE Users ( - user_id BIGINT AUTO_INCREMENT PRIMARY KEY, - username VARCHAR(255) NOT NULL UNIQUE, - email VARCHAR(255) NOT NULL UNIQUE, - password VARCHAR(255) NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +CREATE TABLE `Tags` ( + `tag_id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL UNIQUE ); -CREATE TABLE Boards ( - board_id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL, - description TEXT +CREATE TABLE `Users` ( + `user_id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `username` VARCHAR(255) NOT NULL UNIQUE, + `email` VARCHAR(255) NOT NULL UNIQUE, + `password` VARCHAR(255) NOT NULL, + `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP ); -CREATE TABLE Posts ( - post_id BIGINT AUTO_INCREMENT PRIMARY KEY, - title VARCHAR(255) NOT NULL, - content TEXT NOT NULL, - user_id BIGINT, - board_id BIGINT, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES Users(user_id), - FOREIGN KEY (board_id) REFERENCES Boards(board_id) +CREATE TABLE `Boards` ( + `board_id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(255) NOT NULL, + `description` TEXT ); -CREATE TABLE Comments ( - comment_id BIGINT AUTO_INCREMENT PRIMARY KEY, - content TEXT NOT NULL, - user_id BIGINT, - post_id BIGINT, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES Users(user_id), - FOREIGN KEY (post_id) REFERENCES Posts(post_id) +CREATE TABLE `Posts` ( + `post_id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `title` varchar(255) NOT NULL, + `content` TEXT NOT NULL, + `user_id` BIGINT, + `board_id` BIGINT, + `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + FOREIGN KEY (`user_id`) REFERENCES `Users` (`user_id`), + FOREIGN KEY (`board_id`) REFERENCES `Boards` (`board_id`) ); -CREATE TABLE Tags ( - tag_id BIGINT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL UNIQUE +CREATE TABLE `Comments` ( + `comment_id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `content` TEXT NOT NULL, + `user_id` BIGINT, + `post_id` BIGINT, + `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, + FOREIGN KEY (`user_id`) REFERENCES `Users` (`user_id`), + FOREIGN KEY (`post_id`) REFERENCES `Posts` (`post_id`) ); -CREATE TABLE Post_Tags ( - post_id BIGINT NOT NULL, - tag_id BIGINT NOT NULL, - FOREIGN KEY (post_id) REFERENCES Posts(post_id), - FOREIGN KEY (tag_id) REFERENCES Tags(tag_id) -); \ No newline at end of file +CREATE TABLE `Post_Tags` ( + `post_id` BIGINT, + `tag_id` BIGINT, + FOREIGN KEY (`post_id`) REFERENCES `Posts` (`post_id`), + FOREIGN KEY (`tag_id`) REFERENCES `Tags` (`tag_id`) +); + + diff --git a/src/main/java/com/jungmin/script/Part1.java b/src/main/java/com/jungmin/script/Part1.java index 84c6b55..6b014d7 100644 --- a/src/main/java/com/jungmin/script/Part1.java +++ b/src/main/java/com/jungmin/script/Part1.java @@ -3,55 +3,55 @@ public class Part1 { /* ---------------------------------------------------------------------------------------------- - TODO: 유어클래스의 requirement를 참조하여, migration/schema.sql에 알맞은 테이블을 구성해주세요. + TODO: requirement를 참조하여, migration/schema.sql에 알맞은 테이블을 구성해주세요. */ /* ---------------------------------------------------------------------------------------------- TODO: Q 1-1. 현재 있는 데이터베이스에 존재하는 모든 테이블 정보를 보기위한 SQL을 작성해주세요. */ - public static final String PART1_1 = "show tables"; + public static final String PART1_1 = "SHOW TABLES"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-2. Users 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Users 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_2 = "DESC Users;"; + public static final String PART1_2 = "DESC Users"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-3. Posts 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Posts 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_3 = "DESCRIBE posts"; + public static final String PART1_3 = "DESC Posts"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-4. Tags 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Tags 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_4 = "DESCRIBE Tags"; + public static final String PART1_4 = "DESC Tags"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-5. Post_Tags 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Post_Tags 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_5 = "DESCRIBE Post_Tags"; + public static final String PART1_5 = "DESC Post_tags"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-6. Comments 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Comments 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_6 = "DESCRIBE Comments"; + public static final String PART1_6 = "DESC Comments"; /* ---------------------------------------------------------------------------------------------- TODO: Q 1-7. Boards 테이블의 구조를 보기위한 SQL을 작성해주세요. - 요구사항에 맞는 Boards 테이블을 작성해야만, 테스트를 통과합니다. */ - public static final String PART1_7 = "DESCRIBE Boards"; + public static final String PART1_7 = "DESC Boards"; } diff --git a/src/main/java/com/jungmin/script/Part2.java b/src/main/java/com/jungmin/script/Part2.java index 50b1214..8c91835 100644 --- a/src/main/java/com/jungmin/script/Part2.java +++ b/src/main/java/com/jungmin/script/Part2.java @@ -11,124 +11,129 @@ public class Part2 { ---------------------------------------------------------------------------------------------- TODO: Q 2-2. users 테이블에 존재하는 모든 데이터에서 username 컬럼만을 확인하기 위한 SQL을 작성해주세요. */ - public static final String PART2_2 = "SELECT username FROM Users"; + public static final String PART2_2 = "SELECT u.username FROM Users u"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-3. users 테이블에 데이터를 추가하기 위한 SQL을 작성해주세요.") - 원하는 username, email, password를 사용하시면 됩니다. */ - public static final String PART2_3 = "INSERT INTO Users (username, email, password, created_at) VALUES ('newuser', 'newuser@example.com', 'newpassword', NOW())"; + public static final String PART2_3 = "INSERT INTO Users(username, email, password) VALUES('이름', 'abc@naver.com', '123123')"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-4. users 테이블에서 특정 조건을 가진 데이터를 찾기위한 SQL을 작성해주세요. - 조건 : username이 luckykim이여야 합니다. */ - public static final String PART2_4 = "SELECT * FROM Users WHERE username = 'luckykim'"; + public static final String PART2_4 = "SELECT * FROM Users u WHERE u.username = 'luckykim'"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-5. users 테이블에서 특정 조건을 가진 데이터를 찾기위한 SQL을 작성해주세요. - 조건 : username이 luckykim이 아니여야 합니다. */ - public static final String PART2_5 = "SELECT * FROM Users WHERE username <> 'luckykim'"; + public static final String PART2_5 = "SELECT u.username FROM Users u WHERE u.username <> 'luckykim'"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-6. posts 테이블에 존재하는 모든 데이터에서 title 컬럼만을 찾기 위한 SQL을 작성해주세요. */ - public static final String PART2_6 = "SELECT title FROM Posts"; + public static final String PART2_6 = "SELECT p.title FROM Posts p"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-7. posts의 title과 그 게시글을 작성한 user의 username을 찾기 위한 SQL을 작성해주세요. - 저자가 없더라도, posts의 title을 모두 찾아야합니다. */ - public static final String PART2_7 = "SELECT p.title, u.username FROM Posts p LEFT JOIN Users u ON p.user_id = u.user_id"; + public static final String PART2_7 = "SELECT p.title, u.username FROM Posts p LEFT JOIN Users u ON u.user_id = p.user_id"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-8. posts의 title과 그 게시글을 작성한 user의 username을 찾기 위한 SQL을 작성해주세요. - 저자가 있는 posts의 title만 찾아야합니다. */ - public static final String PART2_8 = "SELECT p.title, u.username FROM Posts p INNER JOIN Users u ON p.user_id = u.user_id"; + public static final String PART2_8 = "SELECT p.title, u.username FROM Posts p JOIN Users u ON u.user_id = p.user_id"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-9. posts 테이블의 데이터를 수정하기 위한 SQL을 작성해주세요. - title이 'New Tech Trends'인 posts 데이터에서 content를 'Updated content'로 수정해야합니다. */ - public static final String PART2_9 = "UPDATE Posts SET content = 'Updated content' WHERE title = 'New Tech Trends'"; + public static final String PART2_9 = "UPDATE Posts p SET p.title = 'Updated content' WHERE p.title = 'New Tech Trends'"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-10. posts 테이블의 데이터를 추가하기 위한 SQL을 작성해주세요. - luckykim이 작성한 게시글을 추가해주세요. 제목과 본문은 자유입니다. (참고: luckykim의 아이디는 1입니다.) */ - public static final String PART2_10 = "INSERT INTO Posts (title, content, user_id, board_id, created_at) VALUES ('New Post', 'This is a new post by luckykim.', 1, 1, CURRENT_TIMESTAMP)"; + public static final String PART2_10 = "INSERT INTO Posts (title, content, user_id, board_id) " + + "VALUES ('title', 'content', 1, 10);"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-11. 어느 board에도 속하지 않는 post의 모든 데이터를 찾기위한 SQL을 작성해주세요.") */ - public static final String PART2_11 = "SELECT * FROM Posts WHERE board_id IS NULL"; + public static final String PART2_11 = "SELECT * FROM Posts p WHERE p.board_id IS NULL"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-12. users 테이블의 user_id가 1인 유저가 작성한 post의 title을 찾기위한 SQL을 작성해주세요. */ - public static final String PART2_12 = "SELECT title FROM Posts WHERE user_id = 1"; + public static final String PART2_12 = "SELECT p.title FROM Posts p WHERE p.user_id = 1"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-13. users 테이블의 user_id가 1인 유저가 작성한 post의 board name을 찾기위한 SQL을 작성해주세요. */ - public static final String PART2_13 = "SELECT b.name FROM Posts p INNER JOIN Boards b ON p.board_id = b.board_id WHERE p.user_id = 1"; + public static final String PART2_13 = "SELECT b.name FROM Boards b JOIN Posts p ON b.board_id = p.board_id WHERE p.user_id = 1"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-14. board의 name이 'General Discussion'인 post의 title, content, created_at을 찾기위한 SQL을 작성해주세요. */ - public static final String PART2_14 = "SELECT p.title, p.content, p.created_at FROM Posts p INNER JOIN Boards b ON p.board_id = b.board_id WHERE b.name = 'General Discussion'"; + public static final String PART2_14 = "SELECT p.title, p.content, p.created_at FROM Posts p JOIN Boards b ON b.board_id = p.board_id WHERE b.name = 'General Discussion'"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-15. luckykim이 작성한 comment의 개수 (컬럼명: CommentCount)를 출력하기 위한 SQL을 작성해주세요. */ - public static final String PART2_15 = "SELECT COUNT(*) AS CommentCount FROM Comments WHERE user_id = 1"; + public static final String PART2_15 = "SELECT COUNT(c.comment_id) as CommentCount FROM Comments c JOIN Users u ON c.user_id = u.user_id WHERE u.username = 'luckykim'"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-16. 각 user(컬럼명: username)가 작성한 comment의 개수 (컬럼명: CommentCount)를 출력하기 위한 SQL을 작성해주세요. - 단, 0개의 comment를 작성한 유저도 모두 출력해야 합니다. */ - public static final String PART2_16 = "SELECT u.username, COUNT(c.comment_id) AS CommentCount FROM Users u LEFT JOIN Comments c ON u.user_id = c.user_id GROUP BY u.username"; + public static final String PART2_16 = "SELECT u.username as username, COUNT(c.comment_id) as CommentCount FROM Comments c LEFT JOIN Users u ON c.user_id = u.user_id GROUP BY u.username"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-17. 각 board의 name과 해당 board에 속한 post의 개수 (컬럼명: PostCount)를 출력하기 위한 SQL을 작성해주세요. */ - public static final String PART2_17 = "SELECT b.name, COUNT(p.post_id) AS PostCount FROM Boards b LEFT JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name"; + public static final String PART2_17 = "SELECT b.name, COUNT(p.post_id) as PostCount FROM Boards b LEFT JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-18. 각 board의 name과 해당 board에 속한 posts 테이블의 content의 평균 길이 (컬럼명: AvgLength)를 출력하기 위한 SQL을 작성해주세요.") */ - public static final String PART2_18 = "SELECT b.name, AVG(CHAR_LENGTH(p.content)) AS AvgLength FROM Boards b LEFT JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name"; + public static final String PART2_18 = "SELECT b.name, AVG(CHAR_LENGTH(p.content)) as AvgLength FROM Boards b LEFT JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-19. 각 board의 name과 해당 board에 속한 posts 테이블의 content의 평균 길이 (컬럼명: AvgLength)를 출력하기 위한 SQL을 작성해주세요. - 단, content가 null인 경우를 제외해야 합니다. */ - public static final String PART2_19 = "SELECT b.name, AVG(CHAR_LENGTH(p.content)) AS AvgLength FROM Boards b LEFT JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name HAVING AvgLength IS NOT NULL "; + public static final String PART2_19 = "SELECT b.name, AVG(CHAR_LENGTH(p.content)) as AvgLength FROM Boards b JOIN Posts p ON b.board_id = p.board_id GROUP BY b.name HAVING AvgLength IS NOT NULL"; /* ---------------------------------------------------------------------------------------------- TODO: Q 2-20. 각 tag의 name과 해당 tag가 달린 post의 개수 (컬럼명: PostCount)를 출력하기 위한 SQL을 작성해주세요. - 단, post에 할당되지 않은 tag의 이름도 모두 출력해야 합니다.") */ - public static final String PART2_20 = "SELECT t.name, COUNT(pt.post_id) AS PostCount FROM Tags t LEFT JOIN Post_Tags pt ON t.tag_id = pt.tag_id GROUP BY t.name"; + public static final String PART2_20 = "SELECT t.name, COUNT(pt.post_id) AS PostCount " + + "FROM Tags t " + + "LEFT JOIN Post_Tags pt ON t.tag_id = pt.tag_id " + + "GROUP BY t.name " + + "ORDER BY t.name"; } From c34106ad8f9bc7c8f2300727f8fd16aee708afc4 Mon Sep 17 00:00:00 2001 From: gwanghui97 Date: Thu, 16 May 2024 18:11:05 +0900 Subject: [PATCH 5/6] finish --- .idea/gradle.xml | 1 + src/main/java/com/jungmin/lib/Mysql.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index f9163b4..ce1c62c 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ +