表CALENDAR_ORG
有以下列和数据
BUSINESS DAY - 20150801 20150801 20150801 20150801
UNIT_CODE - HK IN HK IN
GROUP_NAME - ANG ANG ANG ANG
我想OVER..PARTION BY
用来选择按BUSINESS_DAY
分类的最大值UNIT_CODE
如果使用GROUP BY
,它将是
SELECT MAX(BUSINESS_DAY) AS RUN_DATE FROM CALENDAR_ORG WHERE GROUP_NAME ='ANG' GROUP BY UNIT_CODE;
返回:
20150801
20150801
确实,我得到了 4 条20150801
使用以下查询的记录OVER..PARTITION BY
SELECT MAX(BUSINESS_DAY) OVER (PARTITION BY UNIT_CODE) AS RUN_DATE FROM CALENDAR_ORG WHERE GROUP_NAME='ANG';
20150801
20150801
20150801
20150801
预期的结果应该是
20150801
20150801