有一个表 sheet_iprocess 里面有 attachment_id ,sheet_id ,process_id 主键为process_id 我想把表中sheet_id = ‘00006-1' 的所有记录的最后一条中的attachment_id 修改成 521如何写这个update语句啊update ws_bffaultsheet_iprocess s set s.attachment_id = 521
where s.old_sheet_id='00006-1' and rownum=1 order by process_id desc
where s.old_sheet_id='00006-1' and rownum=1 order by process_id desc
rownum=1 order by process_id desc
肯定不行
where s.old_sheet_id='00006-1' and not exists(select 1 from ws_bffaultsheet_iprocess t where t.process_id >s.process_id );
试试看?
set s.attachment_id = 521
where process_id = (select max(process_id)
from ws_bffaultsheet_iprocess
where old_sheet_id = '00006-1')
update sheet_iprocess a set a.attachment_id='521' where process_id=(select max(b.process_id) from sheet_iprocess b where b.sheet_id='00006-1' )
update sheet_iprocess s set s.attachment_id = 521
where s.process_id =(
select ss.p_id from (
select last(process_id)over(partition by sheet_id) p_id from sheet_iprocess) ss
)
and s.sheet_id = ‘00006-1'