2017-10-16 126 views
0

我想基於當分支ID和員工ID相同甲骨文 - 過濾重複的記錄

注OPEN_DATE過濾重複行:我拉從多個tables.I這些列試圖找到其他職位的答案但找不到。

錶行

OPENED_DATE BRANCH_ID EMPLOYEE_ID 
01/13/2014  100  100121  <- FILTER(SELECT ONLY LATEST OPENED_DATE) 
01/29/2014  100  100121  <- FILTER(SELECT ONLY LATEST OPENED_DATE) 
02/03/2014  100  100121 
02/03/2014  100  100150 

在此先感謝。

+0

使用分析:'MAX(opened_date)以上(分區由Branch_ID,的Employee_ID)作爲Opened_Date' [DOCS](https://docs.oracle.com/cloud/latest/db112/SQLRF/functions098。 htm#SQLRF00666)根據需要確保按適當的字段分組。 – xQbert

+0

-------- SELECT T_EMPLOYEE_ACCOUNT.EMPLOYEE_ID, T_EMPLOYEE.ENTRY_ID, T_EMPLOYEE_ACCOUNT.BRANCH_ID, T_EMPLOYEE_ACCOUNT.EMPLOYEE_ID, T_EMPLOYEE.OPENED_ID FROM T_EMPLOYEE_ACCOUNT JOIN T_EMPLOYEE_ACCOUNT.ENTRY_ID = T_EMPLOYEE.ENTRY_ID; – Cmen535

+0

from/join在語法上不正確。如果您加入T_EMPLOYEE,您需要先執行此操作,然後使用'on'子句顯示它們之間的關係。 'FROM T_EMPLOYEE_ACCOUNT INNER JOIN T_EMPLOYEE on T_EMPLOYEE_ACCOUNT.ENTRY_ID = T_EMPLOYEE.ENTRY_ID;' – xQbert

回答

0

您可以在branchid上使用行號,並按降序使用date命令。

SELECT t1.* 
FROM (SELECT OPENED_DATE 
      , BRANCH_ID 
      , EMPLOYEE_ID 
      , ROW_NUMBER() (OVER PARTITION BY BRANCH_ID , EMPLOYEE_ID ORDER BY OPENED_DATE desc) rn 
     FROM table) as t1 
WHERE rn=1 
+0

似乎我錯過了一些東西。以下是我的實際查詢--------選擇T_EMPLOYEE_ACCOUNT.EMPLOYEE_ID, T_EMPLOYEE.ENTRY_ID, T_EMPLOYEE_ACCOUNT.BRANCH_ID, T_EMPLOYEE_ACCOUNT.EMPLOYEE_ID, T_EMPLOYEE.OPENED_ID FROM T_EMPLOYEE_ACCOUNT JOIN T_EMPLOYEE_ACCOUNT.ENTRY_ID = T_EMPLOYEE。 ENTRY_ID; – Cmen535