[Programmers_SQL] 10. 조건에 부합하는 중고거래 댓글 조회하기

문정준's avatar
Feb 28, 2025
[Programmers_SQL] 10. 조건에 부합하는 중고거래 댓글 조회하기
💡
프로그래머스 SELECT 10. 조건에 부합하는 중고거래 댓글 조회하기

1. 문제 설명

notion image
 

2. 문제

notion image

3. 예시

notion image
 

주의 사항

notion image

4. 문제 풀이

SELECT a.title, a.board_id, b.reply_id, b.writer_id, b.contents, date_format(b.created_date, '%Y-%m-%d') created_date from USED_GOODS_BOARD a inner join USED_GOODS_REPLY b on a.board_id = b.board_id where a.created_date between '2022-10-01' and '2022-10-31' order by b.created_date asc, a.title asc;
  • 1 Line : 게시글 제목, 게시글 ID, 댓글 ID, 댓글 작성자 ID, 댓글 내용, 댓글 작성일을 조회
    • 댓글 작성일의 형식이 ‘0000-00-00’ : date_format
      • SELECT a.title, a.board_id, b.reply_id, b.writer_id, b.contents, date_format(b.created_date, '%Y-%m-%d') created_date
  • 2 Line : USED_GOODS_BOARD, USED_GOODS_REPLY의 두 테이블에서 출력하되, 게시글 ID가 동일한 데이터만 뽑기
    • from USED_GOODS_BOARD a inner join USED_GOODS_REPLY b
  • 3 Line : 두 테이블 내에서 게시글 ID가 동일한 데이터만 뽑기
    • on a.board_id = b.board_id
  • 4 Line : 게시글 작성일이 2022년 10월인 데이터만 출력
    • where a.created_date between '2022-10-01' and '2022-10-31'
  • 5 Line : 댓글 작성일을 기준으로 내림차순, 게시글 제목을 기준으로 오름차순 정렬
    • order by b.created_date asc, a.title asc;

5. 결과 확인

notion image
notion image
Share article

sxias