gpt4 book ai didi

sql - oracle中row_number()可以忽略null吗

转载 作者:行者123 更新时间:2023-12-05 01:33:59 25 4
gpt4 key购买 nike

我有这样的数据

---------------------------
| code | other column
---------------------------
| C | a
| null | a
| A | a
| null | a
| null | a
----------------------------

如何在不计算空列的情况下编写查询来获取 row_number。

----------------------------------
| id | code | other column |
----------------------------------
| 1 | C | a
| | null | a
| 2 | A | a
| | null | a
| | null | a
----------------------------------

最佳答案

好吧,不具体。但是你可以通过使用条件逻辑得到你想要的:

select (case when code is not null
then row_number() over (partition by (case when code is not null then 1 else 0 end)
order by . . .
)
end) as id

我不清楚 order by 是什么 row_number() 是什么 。 . . 表示。

关于sql - oracle中row_number()可以忽略null吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31023790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com