可以在Oracle中row_number()忽略null

LLF*_*LLF 3 sql oracle

我有这样的数据

---------------------------
|   code    | other column
---------------------------
|   C       |    a
|   null    |    a
|   A       |    a
|   null    |    a
|   null    |    a
----------------------------
Run Code Online (Sandbox Code Playgroud)

我如何编写查询以获取row_number而不计算空列。

----------------------------------
| id  |   code    | other column |
----------------------------------
| 1   |   C       |    a
|     |   null    |    a
| 2   |   A       |    a
|     |   null    |    a
|     |   null    |    a
----------------------------------
Run Code Online (Sandbox Code Playgroud)

Gor*_*off 6

好吧,不具体。但是,您可以通过使用条件逻辑来获得所需的内容:

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
Run Code Online (Sandbox Code Playgroud)

目前尚不清楚对我来说什么order by是对的row_number()这是什么. . .手段。