Skip to content

Commit

Permalink
Merge pull request #19 from SSUMC-6th/ming/#17
Browse files Browse the repository at this point in the history
[ming] Chpater05_실전 SQL - 어떤 Query를 작성해야 할까?
  • Loading branch information
qzzloz authored May 19, 2024
2 parents 4d3604b + 7faf1dd commit 387d0d6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/mission/chapter5/chapter5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- 1. 내가 진행중, 진행 완료한 미션 모아서 보는 쿼리(페이징 포함)
SELECT * FROM user_mission as um
WHERE user_id = 1 --(사용자 아이디)
AND mission_status in ("in_progress", "completed")
ORDER BY um.updated_at DESC
LIMIT 10 offset (n-1)*10;

-- 2. 리뷰 작성하는 쿼리, 사진의 경우는 일단 배제
INSERT INTO review values(1, "가게명", 1, 5.0, "맛있다ㅏ");

-- 3. 홈 화면 쿼리 (현재 선택 된 지역에서 도전이 가능한 미션 목록, 페이징 포함)
SELECT M.mission_id, M.point, DATEDIFF(M.due_date, NOW())
FROM mission AS M
JOIN store S ON S.store_id = M.store_id
WHERE S.region_id = (SELECT region_id R FROM region where R.name = "지역명")
AND M.due_date < (SELECT due_date FROM mission WHERE mission_id = 4 -- 4: 마지막으로 조회한 mission id)
ORDER BY M.due_date LIMIT 15;

-- 4. 마이 페이지 화면 쿼리
SELECT nickname, email, phone_number, points FROM user
WHERE user_id = 1; --사용의 아이디

0 comments on commit 387d0d6

Please sign in to comment.