with t as (
select 'AA-00001152' itemid from dual union all
select 'AA-00001152' from dual union all
select 'AA-00001153' from dual union all
select 'AA-00001154' from dual union all
select 'AA-00001154' from dual union all
select 'CC-254565' from dual union all
select 'AA-00001156' from dual union all
select 'AA-00001156' from dual union all
select 'BB-00001200' from dual
)
select 14999 + dense_rank() over(order by itemid) as seq_no,
itemid
from t
order by seq_no
这里我为多个itemId生成了seq_no,但我试图在seq_no列中更新,这会抛出错误,说子查询返回多行。请帮助更新查询。感谢。
我的更新查询: -
update test
set seq_num =14999 + dense_rank() over(order by itemid)
where item_type='non_product')
答案 0 :(得分:0)
在SQL Server中,您可以使用可更新的CTE:
with toupdate as (
select dense_rank() over (order by itemid) as seqnum,
t.*
from t
)
update toupdate
set seq_num = 14999 + seqnum
where item_type = 'non_product';
但是,我怀疑你并没有真正使用SQL Server。此语法在大多数其他数据库中不起作用。