본문 바로가기
MS-SQL

PARTITION BY

by 캡틴노랑이 2019. 1. 14.
반응형

PARTITION BY

GROUP BY 사용하지 않고, COUNT 조회 하기
SELECT *
FROM (
	SELECT RANK() OVER (PARTITION BY ORD_YMD, ORD_NUM ORDER BY SEND_DT desc) AS SEND_RANK
		 , ORD_YMD
         , ORD_NUM
         , SEND_DT
         , SEND_YN
		 , COUNT(*) OVER (PARTITION BY ORD_YMD, ORD_NUM) CNT
	  FROM SM_MAIL_SEND
	 WHERE 1=1
	   AND TMPL = 'AAA'
    ) A
WHERE SEND_RANK = 1

반응형

댓글