WITH A AS(
SELECT WRITER_ID, TOTAL_SALES
FROM( 
SELECT 
WRITER_ID, SUM(PRICE) AS TOTAL_SALES
FROM USED_GOODS_BOARD
WHERE STATUS = 'DONE'
GROUP BY WRITER_ID
    )
WHERE TOTAL_SALES >= '700000'
    )

SELECT A.WRITER_ID AS USER_ID, U.NICKNAME, A.TOTAL_SALES
FROM A JOIN USED_GOODS_USER U ON(A.WRITER_ID = U.USER_ID)
ORDER BY TOTAL_SALES ASC
;

 


<포인트 정리>

 

1. JOIN 문법 조심할 점.

 

1) AS 사용 금지

 

FROM A JOIN USED_GOODS_USER U ON(A.WRITER_ID = U.USER_ID)

 

여기서

 

FROM A JOIN USED_GOODS_USER  AS U ON(A.WRITER_ID = U.USER_ID)

-> 이럼 에러난다.

 

2) 예약어 사용금지(특히 USER)

 

FROM A JOIN USED_GOODS_USER  USER ON(A.WRITER_ID = U.USER_ID)

-> 이럼 에러난다.

+ Recent posts