https://school.programmers.co.kr/learn/courses/30/lessons/164668
정답
SELECT B.USER_ID, B.NICKNAME, SUM(A.PRICE) AS TOTAL_SALES
FROM USED_GOODS_BOARD A
JOIN USED_GOODS_USER B ON A.WRITER_ID = B.USER_ID
WHERE A.STATUS = 'DONE'
GROUP BY B.USER_ID, B.NICKNAME
HAVING SUM(A.PRICE) >= 700000
ORDER BY TOTAL_SALES ;
풀이
Step 1) Group by
SELECT B.USER_ID, B.NICKNAME AS TOTAL_SALES
FROM USED_GOODS_BOARD A INNER JOIN USED_GOODS_USER B
ON A.WRITER_ID = B.USER_ID
WHERE A.STATUS = 'DONE'
;
step 1-1 ) user_id,total_sales 요약하기
SELECT B.USER_ID, B.NICKNAME,sum(A.price) AS TOTAL_SALES
FROM USED_GOODS_BOARD A INNER JOIN USED_GOODS_USER B
ON A.WRITER_ID = B.USER_ID
WHERE A.STATUS = 'DONE'
GROUP BY B.USER_ID, B.NICKNAME
;
step2 ) Having 으로 group by 조건 붙히기
SELECT B.USER_ID, B.NICKNAME,sum(A.price) AS TOTAL_SALES
FROM USED_GOODS_BOARD A INNER JOIN USED_GOODS_USER B
ON A.WRITER_ID = B.USER_ID
WHERE A.STATUS = 'DONE'
GROUP BY B.USER_ID, B.NICKNAME
HAVING SUM(A.PRICE) >= 700000
;
'DB > 프로그래머스' 카테고리의 다른 글
[Oracle] 오랜 기간 보호한 동물(2) (0) | 2024.09.23 |
---|---|
[Oracle] 즐겨찾기가 가장 많은 식당 정보 출력하기 (1) | 2024.09.23 |
[Oracle] 조회수가 가장 많은 중고거래 게시판의 첨부파일 조회하기 (0) | 2024.09.23 |
[ORACLE] 이름에 el이 들어가는 동물 찾기 (0) | 2024.09.09 |
[ORACLE] 중성화 여부 파악하기 (0) | 2024.09.09 |