2016-09-18 2 views
0

Enddate 및 CD_TYPE_COMMENTS 필드를 기반으로 TX_Comments를 그룹화하라는 메시지가 표시되었습니다. 출력은 다음 집계 데이터에 싶지 않아, CD_TYPE_COMMENTS 당 최신 행 수와 마지막 행을 원하는 경우그룹 두 개의 필드를 기반으로 한 설명

ID_EMPLOYEE ID_HEALTH_ASSESSMENT   CD_TYPE_COMMENT ENDDATE TX_COMMENT 
0M00910044 37754 Validation   18.06.2013   Record validated. 
0M00910044 37754 Validation   20.05.2013   Record validated. 
0M00910044 37754 Result    26.07.2013   Created. 
0M00910044 37754 Appointment   18.06.2013   Pls cancel due to      work commitments. 
0M00910044 37754 Appointment   25.06.2013   Confirmed (via Import) 
0M00910044 37754 Ellipse Difference 23.07.2013 The following Employee Details have been updated: 
0M00910044 37754 General    26.07.2013 Record complete 
0M00910044 37754 Validation   20.05.2013 Record created. 
0M00910044 37754 Appointment   09.07.2013 As advised by Mick Maskell. To be rescheduled to another date. 
0M00910044 37754 Appointment   09.07.2013 Late cancellation charges will apply. 
0M00910044 37754 Appointment   09.07.2013 Confirmed (via Import) 
0M00910044 37754 Ellipse Difference 23.07.2013 The following Employee Details have been updated and should be checked for impact on this HA: 
0M00910044 37754 Validation   20.05.2013 Manually created due to import exception error - Test Type could not be determined. Create HA manually. Has a valid RISI. 
0M00910044 37754 Appointment   25.06.2013 Preferences provided. 
0M00910044 37754 Ellipse Difference 04.07.2013 The following Employee Details have been updated and should be checked for impact on this HA: 
0M00910044 37754 Validation   09.07.2013 Record validated. 
0M00910044 37754 Appointment   18.06.2013 Cancelled (by Railcorp) 
0M00910044 37754 Appointment   09.07.2013 Cancelled (by Railcorp) 
0M00910044 37754 Appointment   24.05.2013 Preferences provided. 
0M00910044 37754 Appointment   28.05.2013 Confirmed (via Import) 
0M00910044 37754 Appointment   09.07.2013 Preferences provided. 
+1

그렇다면 질문은 무엇입니까? –

+0

"CD_TYPE_COMMENT 및 ENDDATE를 기반으로 TX_Comment 그룹", 작성한 'SQL'쿼리 또는 주석입니까? –

+0

그것의 코멘트. MAX, Partition, GroupBy 기능을 사용했지만 예상되는 출력을 얻지 못했습니다. – Zoelte

답변

1

을 종료 날짜한다. 마지막 하나만 선택하면됩니다. 당신이 정말로뿐만 아니라 직원 당이 정보를 원하는 경우

select t.* 
from t 
where t.enddate = (select max(t2.enddate) 
        from t t2 
        where t2.CD_TYPE_COMMENT = t.CD_TYPE_COMMENT 
       ); 

는, 다음의 상관 관계 절에 and t2.Employee_ID = t.Employee_ID 포함

여기 하나의 방법입니다.

+0

와우! 이것은 SQL의 SQL과 같을 수 있습니다. SQL 자체에서 일부 SQL을'by by by by '또는'by by by group' 구현. –

+0

@Gordon 위의 하위 쿼리를 약간 변경했는데 완벽하게 작동했습니다. 당신의 도움을 주셔서 감사합니다 :) – Zoelte

관련 문제