select 重复行之一,其他行保持为 NULL SQL Netezza
select one of the duplicate rows and keep the others to be NULL SQL Netezza
请在下面 table 中更改某些列的行,而其他一些列是重复的,因此我需要获取更改后的行并仅保留重复行中的一条记录和让其他人为 NULL
LOG_DATE |ITEM_ID |PROBLEM |CALL_DATE |UCID |ID |ACCOUNT_NO|CALL_STATUS|
----------|--------|--------|-----------|---------|---------|----------|-----------|
2020-10-23|76409075|TYPE 1 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-07|76044107|TYPE 2 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-18|76297468|TYPE 3 |2020-10-23 |603405210|133283340|3825551 |Answered |
预期结果
LOG_DATE |ITEM_ID |PROBLEM |CALL_DATE |UCID |ID |ACCOUNT_NO|CALL_STATUS|
----------|--------|--------|-----------|---------|---------|----------|-----------|
2020-10-23|76409075|TYPE 1 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-07|76044107|TYPE 2 |NULL |NULL |NULL |NULL |NULL |
2020-10-18|76297468|TYPE 3 |NULL |NULL |NULL |NULL |NULL |
我不认为我真的推荐这个,但你可以这样做:
select LOG_DATE, ITEM_ID, PROBLEM,
(case when row_number() over (partition by CALL_DATE, UCID, ID, ACCOUNT_NO, CALL_STATUS order by log_date desc) = 1
then call_date
end) as call_date,
(case when row_number() over (partition by CALL_DATE, UCID, ID, ACCOUNT_NO, CALL_STATUS order by log_date desc) = 1
then ucid
end) as ucid,
. . .
from t;
请在下面 table 中更改某些列的行,而其他一些列是重复的,因此我需要获取更改后的行并仅保留重复行中的一条记录和让其他人为 NULL
LOG_DATE |ITEM_ID |PROBLEM |CALL_DATE |UCID |ID |ACCOUNT_NO|CALL_STATUS|
----------|--------|--------|-----------|---------|---------|----------|-----------|
2020-10-23|76409075|TYPE 1 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-07|76044107|TYPE 2 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-18|76297468|TYPE 3 |2020-10-23 |603405210|133283340|3825551 |Answered |
预期结果
LOG_DATE |ITEM_ID |PROBLEM |CALL_DATE |UCID |ID |ACCOUNT_NO|CALL_STATUS|
----------|--------|--------|-----------|---------|---------|----------|-----------|
2020-10-23|76409075|TYPE 1 |2020-10-23 |603405210|133283340|3825551 |Answered |
2020-10-07|76044107|TYPE 2 |NULL |NULL |NULL |NULL |NULL |
2020-10-18|76297468|TYPE 3 |NULL |NULL |NULL |NULL |NULL |
我不认为我真的推荐这个,但你可以这样做:
select LOG_DATE, ITEM_ID, PROBLEM,
(case when row_number() over (partition by CALL_DATE, UCID, ID, ACCOUNT_NO, CALL_STATUS order by log_date desc) = 1
then call_date
end) as call_date,
(case when row_number() over (partition by CALL_DATE, UCID, ID, ACCOUNT_NO, CALL_STATUS order by log_date desc) = 1
then ucid
end) as ucid,
. . .
from t;