From 913cf5ef11a2de65160b8d912dde0521a217f143 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Mon, 2 Dec 2024 10:26:13 +0900 Subject: [PATCH 1/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[CT]=20?= =?UTF-8?q?=EC=88=A0=EB=9E=98=EC=9E=A1=EA=B8=B0=20=EC=B2=B4=EC=8A=A4=5F241?= =?UTF-8?q?202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...352\270\260_\354\262\264\354\212\244.java" | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "CodeTree/2019-2020\353\205\204/JW_\354\210\240\353\236\230\354\236\241\352\270\260_\354\262\264\354\212\244.java" diff --git "a/CodeTree/2019-2020\353\205\204/JW_\354\210\240\353\236\230\354\236\241\352\270\260_\354\262\264\354\212\244.java" "b/CodeTree/2019-2020\353\205\204/JW_\354\210\240\353\236\230\354\236\241\352\270\260_\354\262\264\354\212\244.java" new file mode 100644 index 00000000..54942d42 --- /dev/null +++ "b/CodeTree/2019-2020\353\205\204/JW_\354\210\240\353\236\230\354\236\241\352\270\260_\354\262\264\354\212\244.java" @@ -0,0 +1,91 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class JW_술래잡기_체스 { + + static int[] dy = { 0, -1, -1, 0, 1, 1, 1, 0, -1 }; + static int[] dx = { 0, 0, -1, -1, -1, 0, 1, 1, 1 }; + static int max = 0; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + int[][][] board = new int[4][4][2]; + for (int i = 0; i < 4; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < 4; j++) { + int p = Integer.parseInt(st.nextToken()); + int d = Integer.parseInt(st.nextToken()); + board[i][j] = new int[] { p, d }; + } + } + policeMove(0, 0, 0, board); + System.out.println(max); + } + + // 경찰 이동(재귀) + private static void policeMove(int sum, int y, int x, int[][][] board) { + sum += board[y][x][0]; // 해당 좌표의 값을 합 + max = Math.max(max, sum); // 최댓값 갱신 + board[y][x][0] = 0; // 해당 좌표의 값을 초기화 + int d = board[y][x][1]; // 해당 좌표의 방향 + doDookMove(y, x, board); // 도둑 이동 + // 경찰이 이동할 수 있는 방향을 모두 재귀적으로 탐색 + for (int i = 1; i <= 3; i++) { + int ny = y + dy[d] * i, nx = x + dx[d] * i; + // 이동할 수 있다면 + if (isValid(ny, nx) && board[ny][nx][0] != 0) { + int[][][] nextBoard = copyBoard(board); + policeMove(sum, ny, nx, nextBoard); // 재귀 호출 + } + } + } + + // 도둑 이동 + private static void doDookMove(int py, int px, int[][][] board) { + // 순서에 따라서 이동 + next: for (int p = 1; p <= 16; p++) { + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + // 순서에 맞는 좌표를 찾았다면 + if (board[y][x][0] == p) { + int d = board[y][x][1]; + int ny = y + dy[d], nx = x + dx[d]; + // 이동할 수 있는 좌표가 등장할 때까지 회전 + while (!isValid(ny, nx) || (ny == py && nx == px)) { + d++; + d %= 9; + if (d == 0) + d = 1; + ny = y + dy[d]; + nx = x + dx[d]; + } + swap(y, x, ny, nx, board); // 스왑 + board[ny][nx][1] = d; // 새로운 방향으로 변경 + continue next; // 발견했다면 다음 순서 진행 + } + } + } + + // 두 좌표에 있는 원소를 스왑해주는 함수 + private static void swap(int y, int x, int ny, int nx, int[][][] board) { + int[] temp = board[y][x]; + board[y][x] = board[ny][nx]; + board[ny][nx] = temp; + } + + // 기존의 배열을 복사하여 다음 배열을 만들어주는 함수 + private static int[][][] copyBoard(int[][][] board) { + int[][][] nextBord = new int[4][4][2]; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + nextBord[i][j] = board[i][j].clone(); + return nextBord; + } + + // 경계 체크 함수 + private static boolean isValid(int y, int x) { + return 0 <= y && y < 4 && 0 <= x && x < 4; + } +} \ No newline at end of file From 8142b0e3bdfd062a51d8a85e1e38d34aa4ff1f73 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Tue, 3 Dec 2024 16:00:40 +0900 Subject: [PATCH 2/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201194?= =?UTF-8?q?=20=EB=8B=AC=EC=9D=B4=20=EC=B0=A8=EC=98=A4=EB=A5=B8=EB=8B=A4,?= =?UTF-8?q?=20=EA=B0=80=EC=9E=90=5F241203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000\353\262\210/JW_1194.java" | 91 ++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 "BOJ/1000-5000\353\262\210/JW_1194.java" diff --git "a/BOJ/1000-5000\353\262\210/JW_1194.java" "b/BOJ/1000-5000\353\262\210/JW_1194.java" new file mode 100644 index 00000000..9d02a0ba --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/JW_1194.java" @@ -0,0 +1,91 @@ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.StringTokenizer; + +public class JW_1194 { + + static int n, m; + static char[][] board; + + static int[] dy = { 1, -1, 0, 0 }; + static int[] dx = { 0, 0, 1, -1 }; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + n = Integer.parseInt(st.nextToken()); + m = Integer.parseInt(st.nextToken()); + board = new char[n][m]; + int sy = 0, sx = 0; + for (int i = 0; i < n; i++) { + String line = br.readLine(); + for (int j = 0; j < m; j++) { + board[i][j] = line.charAt(j); + // 초기 위치 설정 + if (board[i][j] == '0') { + sy = i; + sx = j; + } + } + } + // 열쇠 상태에 따라 방문 체크를 해주기 위해서 3차원 방문 체크 생성 + boolean[][][] visited = new boolean[n][m][1 << 6]; + Deque dq = new ArrayDeque<>(); + dq.offer(new int[] { sy, sx, 0, 0 }); + visited[sy][sx][0] = true; + + // BFS + while (!dq.isEmpty()) { + int[] cur = dq.poll(); + // 현재 좌표, 열쇠 상태, 움직임 횟수 + int y = cur[0], x = cur[1], keys = cur[2], moveCnt = cur[3]; + // 종료 조건 + if (board[y][x] == '1') { + System.out.println(moveCnt); + return; + } + for (int i = 0; i < 4; i++) { + int ny = y + dy[i], nx = x + dx[i]; + int newKeys = keys; + + // 이동 조건 + if (!isValid(ny, nx) || board[ny][nx] == '#') { + continue; + } + + // 열쇠일 경우 + if (isKey(ny, nx)) + // 해당 열쇠 추가 + newKeys |= (1 << (board[ny][nx] - 'a')); + + // 문일 경우, 열쇠가 없다면 이동 불가 + else if (isDoor(ny, nx) && (keys & (1 << (board[ny][nx] - 'A'))) == 0) + continue; + + // 현재 열쇠 상태에서 방문하지 않았다면 방문 + if (!visited[ny][nx][newKeys]) { + dq.offer(new int[] { ny, nx, newKeys, moveCnt + 1 }); + visited[ny][nx][newKeys] = true; + } + } + } + System.out.println(-1); + } + + // 열쇠 체크 + private static boolean isKey(int y, int x) { + return 'a' <= board[y][x] && board[y][x] <= 'f'; + } + + // 문 체크 + private static boolean isDoor(int y, int x) { + return 'A' <= board[y][x] && board[y][x] <= 'F'; + } + + // 경계 체크 + private static boolean isValid(int y, int x) { + return 0 <= y && y < n && 0 <= x && x < m; + } +} \ No newline at end of file From 289ada08e496c811b505907875507096192277d7 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Wed, 4 Dec 2024 10:17:54 +0900 Subject: [PATCH 3/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=208979?= =?UTF-8?q?=20=EC=98=AC=EB=A6=BC=ED=94=BD=5F241204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/5001-10000\353\262\210/JW_8979.java" | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 "BOJ/5001-10000\353\262\210/JW_8979.java" diff --git "a/BOJ/5001-10000\353\262\210/JW_8979.java" "b/BOJ/5001-10000\353\262\210/JW_8979.java" new file mode 100644 index 00000000..5c139b33 --- /dev/null +++ "b/BOJ/5001-10000\353\262\210/JW_8979.java" @@ -0,0 +1,37 @@ +import java.util.Arrays; + +public class JW_8879 { + + public static void main(String[] args) throws Exception { + int n = read(), k = read(); + int[][] arr = new int[n][4]; + for (int i = 0; i < n; i++) + arr[i] = new int[] { read(), read(), read(), read() }; + // 정렬 + Arrays.sort(arr, (o1, o2) -> o2[1] != o1[1] ? o2[1] - o1[1] : o2[2] != o1[2] ? o2[2] - o1[2] : o2[3] - o1[3]); + int rank = 1; + for (int i = 0; i < n; i++) { + // 등수 증가 조건 + if (i > 0 && !isSame(arr[i - 1], arr[i])) + rank = i + 1; + // 종료 조건 + if (arr[i][0] == k) + break; + } + System.out.println(rank); + } + + // 동일 점수 확인 + private static boolean isSame(int[] A, int[] B) { + return A[1] == B[1] && A[2] == B[2] && A[3] == B[3]; + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + while ((c = System.in.read()) >= 48) + n = (n << 3) + (n << 1) + (c & 15); + if (c == 13) + System.in.read(); + return n; + } +} \ No newline at end of file From fc64e2afa25d995bb46b1ce0436f2a9d930466d8 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Thu, 5 Dec 2024 14:02:16 +0900 Subject: [PATCH 4/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[BOJ]=201749?= =?UTF-8?q?=20=EC=A0=90=EC=88=98=EB=94=B0=EB=A8=B9=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "BOJ/1000-5000\353\262\210/JW_1749.java" | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "BOJ/1000-5000\353\262\210/JW_1749.java" diff --git "a/BOJ/1000-5000\353\262\210/JW_1749.java" "b/BOJ/1000-5000\353\262\210/JW_1749.java" new file mode 100644 index 00000000..2cdafed0 --- /dev/null +++ "b/BOJ/1000-5000\353\262\210/JW_1749.java" @@ -0,0 +1,31 @@ +public class JW_1749 { + + public static void main(String[] args) throws Exception { + int n = read(), m = read(), max = Integer.MIN_VALUE; + int[][] dp = new int[n + 1][m + 1]; + for (int i = 1; i < n + 1; i++) + for (int j = 1; j < m + 1; j++) + // (i, j)까지의 누적합 + dp[i][j] = read() + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]; + for (int i = 1; i < n + 1; i++) + for (int j = 1; j < m + 1; j++) + for (int k = 1; k < i + 1; k++) + for (int l = 1; l < j + 1; l++) { + // 부분 배열의 누적합 구하기 + max = Math.max(max, dp[i][j] - dp[k - 1][j] - dp[i][l - 1] + dp[k - 1][l - 1]); + } + System.out.println(max); + } + + private static int read() throws Exception { + int c, n = System.in.read() & 15; + boolean m = n == 13; + if (m) + n = System.in.read() & 15; + while ((c = System.in.read()) >= 48) + n = (n << 3) + (n << 1) + (c & 15); + if (c == 13) + System.in.read(); + return m ? ~n + 1 : n; + } +} \ No newline at end of file From d1cd298986ec77ec98db6ecb66c48de0d6136302 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Thu, 5 Dec 2024 15:37:03 +0900 Subject: [PATCH 5/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[PG]=2025013?= =?UTF-8?q?5=20[PCCP=20=EA=B8=B0=EC=B6=9C=EB=AC=B8=EC=A0=9C]=203=EB=B2=88?= =?UTF-8?q?=20/=20=EC=95=84=EB=82=A0=EB=A1=9C=EA=B7=B8=20=EC=8B=9C?= =?UTF-8?q?=EA=B3=84=5F241205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level2/JW_250135.java | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Programmers/Level2/JW_250135.java diff --git a/Programmers/Level2/JW_250135.java b/Programmers/Level2/JW_250135.java new file mode 100644 index 00000000..0419f3a4 --- /dev/null +++ b/Programmers/Level2/JW_250135.java @@ -0,0 +1,62 @@ +class Solution { + public int solution(int h1, int m1, int s1, int h2, int m2, int s2) { + int answer = 0; + int now = h1 * 3600 + m1 * 60 + s1; + int end = h2 * 3600 + m2 * 60 + s2; + // 시작부터 겹치고 시작할 경우 + if (now == 0 || now == 43200) + answer++; + while (now < end) { + double[] nowAngles = calculateAndgles(now); + double[] nextAngles = calculateAndgles(now + 1); + boolean isHourMatched = chkHour(nowAngles, nextAngles); + boolean isMinMatched = chkMin(nowAngles, nextAngles); + if (isHourMatched) + answer++; + if (isMinMatched) + answer++; + // 둘 다 겹칠 경우에는 한번만 체크 + if (isHourMatched && isMinMatched) + if (nextAngles[0] == nextAngles[1]) + answer--; + now++; + } + return answer; + } + + private double[] calculateAndgles(int time) { + double[] angles = new double[3]; + double h = time / 3600, m = time % 3600 / 60, s = time % 3600 % 60; + // 시침의 현재 각도 + angles[0] = (h % 12) * (360d / 12) + m * (360d / 12 / 60) + s * (360d / 12 / 3600); + // 분침의 현재 각도 + angles[1] = m * (360d / 60) + s * (360d / 60 / 60); + // 초침의 현재 각도 + angles[2] = s * (360d / 60); + return angles; + } + + // 시침 겹침 확인 + private boolean chkHour(double[] now, double[] next) { + double nowSec = now[2], nextSec = next[2]; + // 1초의 움직임 안에 시침이 포함되는가 + if (nowSec < now[0] && next[0] <= nextSec) + return true; + // 59초의 값은 따로 계산 → 원형이기에 각도가 0으로 초기화되기 때문 + if (nowSec == 354d && 354d < now[0]) + return true; + return false; + } + + // 분침 겹침 확인 + private boolean chkMin(double[] now, double[] next) { + double nowSec = now[2], nextSec = next[2]; + // 1초의 움직임 안에 시침이 포함되는가 + if (nowSec < now[1] && next[1] <= nextSec) + return true; + // 59초의 값은 따로 계산 → 원형이기에 각도가 0으로 초기화되기 때문 + if (nowSec == 354d && 354d < now[1]) + return true; + return false; + } +} \ No newline at end of file From 69b322f88f130b7f134bbbd5b3744f3f29dbaf58 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Fri, 6 Dec 2024 13:51:22 +0900 Subject: [PATCH 6/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[PG]=2015036?= =?UTF-8?q?7=20=ED=91=9C=ED=98=84=20=EA=B0=80=EB=8A=A5=ED=95=9C=20?= =?UTF-8?q?=EC=9D=B4=EC=A7=84=ED=8A=B8=EB=A6=AC=5F241206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Programmers/Level3/JW_150367.java | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Programmers/Level3/JW_150367.java diff --git a/Programmers/Level3/JW_150367.java b/Programmers/Level3/JW_150367.java new file mode 100644 index 00000000..10bc9578 --- /dev/null +++ b/Programmers/Level3/JW_150367.java @@ -0,0 +1,38 @@ +class JW_150367 { + public int[] solution(long[] numbers) { + int[] answer = new int[numbers.length]; + for (int i = 0; i < numbers.length; i++) { + String str = toBinaryString(numbers[i]); + // 표현 가능한 포화 이진 트리일 경우 '1' + answer[i] = chkInOrder(str, 0, str.length() - 1) ? 1 : 0; + } + return answer; + } + + // 포화 이진 트리 -> 문자열 길이가 2^n - 1 꼴이 되어야 함 + private String toBinaryString(long number) { + StringBuilder sb = new StringBuilder(Long.toBinaryString(number)); + int n = 1; + while (sb.length() > (1 << n) - 1) { + n++; + } + // 빈 부분 채우기 + sb.insert(0, "0".repeat((1 << n) - 1 - sb.length())); + return sb.toString(); + } + + // 중위 탐색을 진행하면서 불가능한 트리인지 확인 + private boolean chkInOrder(String str, int l, int r) { + // 리프노드 일 경우는 True + if (l == r) + return true; + int rootIdx = (l + r) / 2; + // 루트 노드가 0'일 경우에는 자식에 '1'이 있으면 안됨 + if (str.charAt(rootIdx) == '0') + for (int i = l; i <= r; i++) + if (str.charAt(i) == '1') + return false; + // 다음 중위 탐색 + return chkInOrder(str, l, rootIdx - 1) && chkInOrder(str, rootIdx + 1, r); + } +} \ No newline at end of file From 8a0f568cfb69cc8d13e400a23e4e91d0228fcd87 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Sat, 7 Dec 2024 03:12:45 +0900 Subject: [PATCH 7/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[SQL]=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20=EB=A7=8C?= =?UTF-8?q?=EC=A1=B1=ED=95=98=EB=8A=94=20=EB=AC=BC=EA=B3=A0=EA=B8=B0?= =?UTF-8?q?=EB=B3=84=20=EC=88=98=EC=99=80=20=EC=B5=9C=EB=8C=80=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=B4=20=EA=B5=AC=ED=95=98=EA=B8=B0=5F241210?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...235\264_\352\265\254\355\225\230\352\270\260.sql" | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 "SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" diff --git "a/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" "b/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" new file mode 100644 index 00000000..dcd36dea --- /dev/null +++ "b/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" @@ -0,0 +1,12 @@ +SELECT + COUNT(ID) `FISH_COUNT` + , MAX(LENGTH) `MAX_LENGTH` + , FISH_TYPE +FROM + FISH_INFO +GROUP BY + FISH_TYPE +HAVING + AVG(IFNULL(LENGTH, 10)) >= 33 +ORDER BY + FISH_TYPE \ No newline at end of file From 674d66ea78b1c9113b521ba5b1baf6859a31b697 Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Sat, 7 Dec 2024 03:13:28 +0900 Subject: [PATCH 8/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[SQL]=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20=EB=A7=8C?= =?UTF-8?q?=EC=A1=B1=ED=95=98=EB=8A=94=20=EB=AC=BC=EA=B3=A0=EA=B8=B0?= =?UTF-8?q?=EB=B3=84=20=EC=88=98=EC=99=80=20=EC=B5=9C=EB=8C=80=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=B4=20=EA=B5=AC=ED=95=98=EA=B8=B0=5F241203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git "a/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" "b/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" index dcd36dea..388478a1 100644 --- "a/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" +++ "b/SQL/13\354\243\274\354\260\250/JW_\355\212\271\354\240\225_\354\241\260\352\261\264\354\235\204_\353\247\214\354\241\261\355\225\230\353\212\224_\353\254\274\352\263\240\352\270\260\353\263\204_\354\210\230\354\231\200_\354\265\234\353\214\200_\352\270\270\354\235\264_\352\265\254\355\225\230\352\270\260.sql" @@ -1,6 +1,6 @@ SELECT - COUNT(ID) `FISH_COUNT` - , MAX(LENGTH) `MAX_LENGTH` + COUNT(ID) AS `FISH_COUNT` + , MAX(LENGTH) AS `MAX_LENGTH` , FISH_TYPE FROM FISH_INFO From 436b21be61c65c138495212e8b272d9b1d23298f Mon Sep 17 00:00:00 2001 From: Jewan1120 Date: Sat, 7 Dec 2024 03:42:24 +0900 Subject: [PATCH 9/9] =?UTF-8?q?=EB=B0=B1=EC=A0=9C=EC=99=84:=20[SQL]=20Prod?= =?UTF-8?q?uct=20Price=20at=20a=20Given=20Date=5F241205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JW_Product_Price_at_a_Given_Date.sql" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "SQL/13\354\243\274\354\260\250/JW_Product_Price_at_a_Given_Date.sql" diff --git "a/SQL/13\354\243\274\354\260\250/JW_Product_Price_at_a_Given_Date.sql" "b/SQL/13\354\243\274\354\260\250/JW_Product_Price_at_a_Given_Date.sql" new file mode 100644 index 00000000..eb294d9a --- /dev/null +++ "b/SQL/13\354\243\274\354\260\250/JW_Product_Price_at_a_Given_Date.sql" @@ -0,0 +1,28 @@ +WITH CTE AS ( + SELECT + product_id + , new_price + FROM + products + WHERE + (product_id, change_date) IN + ( + SELECT + product_id + , MAX(change_date) + FROM + Products + WHERE + change_date <= '2019-08-16' + GROUP BY + product_id + ) +) + +SELECT + DISTINCT(A.product_id) + , IFNULL(B.new_price, 10) `price` +FROM + products A + LEFT JOIN CTE B + ON A.product_id = B.product_id \ No newline at end of file