Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoGroove01 committed Oct 9, 2024
2 parents 485e149 + 89fcd1e commit 71fe245
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Binary file added mission/chapter01/week1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 18 additions & 20 deletions mission/chapter02/mission.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,40 @@ SELECT
m.points,
um.status,
um.completed_at
FROM user_missions um
JOIN missions m ON um.mission_id = m.mission_id
JOIN stores s ON m.store_id = s.store_id
WHERE um.user_id = {user_id}
ORDER BY -- 진행중, 시간 순서로 정렬
CASE
WHEN um.status = 'ongoing' THEN 0
ELSE 1
END,
COALESCE(um.completed_at, CURRENT_TIMESTAMP) DESC
LIMIT {limit} OFFSET {offset};
FROM user_missions AS um
JOIN missions AS m ON um.mission_id = m.mission_id
JOIN stores AS s ON m.store_id = s.store_id
WHERE um.user_id = {user_id} AND um.status = 'complete'
LIMIT 10 OFFSET {offset};

-- 리뷰 작성하는 쿼리,
-- * 사진의 경우는 일단 배제
INSERT INTO reviews (user_id, mission_id, store_id, rating, review_text)
VALUES ({user_id}, {mission_id}, {store_id}, {rating}, {review_text});

UPDATE user_missions
SET status = 'reviewed'
WHERE user_id = {user_id} AND mission_id = {mission_id};
SELECT r.rating, r.review_text, r.created_at
FROM review AS r
WHERE r.user_id = {user_id}
LIMIT 10 OFFSET {offset}

-- 홈 화면 쿼리(현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함)
SELECT m.mission_id, s.store_name, m.mission_description, m.points
FROM missions m
JOIN stores s ON m.store_id = s.store_id
FROM missions as m
JOIN stores AS s ON m.store_id = s.store_id
WHERE s.region_id = {region_id}
AND m.mission_id NOT IN (
SELECT mission_id
FROM user_missions
WHERE user_id = {user_id}
)
ORDER BY m.points DESC
LIMIT {limit} OFFSET {offset};
LIMIT 10 OFFSET {offset};

-- 마이 페이지 화면 쿼리
SELECT
u.username, u.email, u.points
u.username, u.email, u.points, (
SELECT r.rating, r.review_text, r.created_at
FROM review AS r
WHERE r.user_id = u.user_id
)
FROM users u
WHERE u.user_id = {user_id}
WHERE u.user_id = {user_id}

0 comments on commit 71fe245

Please sign in to comment.