리뷰를 가장 많이 작성한 회원 이름, 리뷰 텍스트, 리뷰 작성일이 출력. 리뷰 작성일을 기준으로 오름차순, 리뷰 작성일이 같다면 리뷰 텍스트를 기준으로 오름차순 정렬.
문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/131124
SELECT
MEMBER_NAME,
REVIEW_TEXT,
DATE_FORMAT(REVIEW_DATE, '%Y-%m-%d') AS REVIEW_DATE
FROM REST_REVIEW
LEFT JOIN (
SELECT
MEMBER_ID,
RANK() OVER(ORDER BY COUNT(MEMBER_ID) DESC) AS REVIEW_RANK
FROM REST_REVIEW
GROUP BY MEMBER_ID
) AS REST_REVIEW_RANK
ON REST_REVIEW.MEMBER_ID = REST_REVIEW_RANK.MEMBER_ID
LEFT JOIN MEMBER_PROFILE
ON REST_REVIEW.MEMBER_ID = MEMBER_PROFILE.MEMBER_ID
WHERE REVIEW_RANK = 1
ORDER BY REVIEW_DATE, REVIEW_TEXT