0

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

4

1 回答 1

0

问题解决了

SELECT DISTINCT (MAX(BUSINESS_DAY) OVER (PARTITION BY UNIT_CODE)) AS RUN_DATE, UNIT_CODE FROM CALENDAR_ORG WHERE SGROUP_NAME='ANG';

于 2018-05-13T07:43:14.457 回答