DB2选择性选择

nfeuvbwi  于 2023-05-06  发布在  DB2
关注(0)|答案(1)|浏览(257)

是否可能select只从基表列没有列出所有的列,这意味着所有列wihout rn列。
这行不通的。。

select tt.t.*
from (

来源:

select *
from (
    select t.*, row_number() over(partition by id order by anumber) rn 
    from mytable t 
    where option
) tt
where rn = 1
order by id
gcuhipw9

gcuhipw91#

假设这与question相关:
您可以通过将子查询与表连接来实现此操作:

select t.*
from (
    select t.*, row_number() over(partition by id order by anumber) rn    
    from mytable t 
    where option
) tt
inner join mytable t on t.ID = tt.ID and t.ANUMBER = tt.ANUMBER
where rn = 1
order by t.id

相关问题