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 (20230917): 데이터베이스 첫걸음 7장-8장 #17

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
Binary file added Document/2023/0917/taehyun/01_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions Document/2023/0917/taehyun/131123.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- [ Programmers ] 즐겨찾기가 가장 많은 식당 정보 출력하기

-- 중첩 서브쿼리(Nested Subquery)면서 다중열 서브쿼리(Multiple-column Subquery)인 서브쿼리를 사용한 풀이
SELECT
FOOD_TYPE,
REST_ID,
REST_NAME,
FAVORITES
FROM REST_INFO
WHERE (FOOD_TYPE, FAVORITES) IN (
SELECT
FOOD_TYPE,
MAX(FAVORITES) AS MAXIMUM_FAVORITES
FROM REST_INFO
GROUP BY FOOD_TYPE
)
ORDER BY FOOD_TYPE DESC;

19 changes: 19 additions & 0 deletions Document/2023/0917/taehyun/59413.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- [ Programmers ] 입양 시각 구하기 (2)

-- 공통 테이블 표현식(Common Table Expression, CTE)의 재귀적(Recursive) 사용을 통한 풀이
WITH RECURSIVE cte (HOUR) AS (
SELECT 0 AS HOUR
UNION ALL
SELECT HOUR + 1 AS HOUR
FROM cte
WHERE HOUR < 23
)

SELECT
cte.HOUR AS HOUR,
COUNT(ANIMAL_OUTS.ANIMAL_ID) AS COUNT
FROM cte
LEFT JOIN ANIMAL_OUTS
ON cte.HOUR = HOUR(ANIMAL_OUTS.DATETIME)
GROUP BY cte.HOUR
ORDER BY cte.HOUR ASC;
6 changes: 6 additions & 0 deletions Document/2023/0917/taehyun/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mysql:5.7

ENV MYSQL_ROOT_PASSWORD=root
ENV MYSQL_DATABASE=world

COPY ./world.sql /docker-entrypoint-initdb.d/
Loading