我有以下情况:
表员工:
First Name | Last Name | Department | Salary
-----------|-----------|------------|---------
John | Doe | Finance | 20
John | Doe | R&D | 20
John | null | Finance | 20
John | long | Finance | 20
我想要每个(名字,姓氏)1行,除非我们的姓氏中有一个空值,然后我只想要1行(名字,空值)
对于上面的例子,结果是:
First Name | Last Name | Department | Salary
-----------|-----------|------------|---------
John | null | Finance | 20
但如果我没有那个记录,那么结果应该是:
First Name | Last Name | Department | Salary
-----------|-----------|------------|---------
John | Doe | R&D | 20
John | long | Finance | 20
我想答案涉及一些 Partition By-s,但我不确定在哪里。
现在我来到了这个:
SELECT FirstName,LastName, DEPARTMENT,Salary,RK FROM
(
select * from
SELECT EXT.*,
ROW_NUMBER() OVER(PARTITION BY EXT.FirstName,EXT.LastName
ORDER BY rownum ASC) AS RK
FROM Employees EXT
)
WHERE RK = 1 ;
谢谢 !