我有如下结果集:
1001 abcdefg
1001 dghfkdk
1001 lkjkjkl
1002 kkjhjkh
1003 iuoiuoi
1003 kjljklj
我想在第1列中显示一个空值,当它不止一次时。
例如:
1001 abcdefg
null dghfkdk
null lkjkjkl
1002 kkjhjkh
1003 iuoiuoi
null kjljklj
有人可以帮助我吗? 提前谢谢。
答案 0 :(得分:4)
您可以使用row_number:
select case when ranking = 1
then id
else null
end as id
, column_txt
from
(
select id
, column_txt
, row_number() over (partition by id order by column_txt) as ranking
from table
)t