有一个表 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 

解决方案 »

  1.   

    得做个子查询才行吧!
    rownum=1 order by process_id desc 
    肯定不行
      

  2.   

    update ws_bffaultsheet_iprocess s set s.attachment_id = 521 where process_id =(select process_id from ws_bffaultsheet_iprocess where old_sheet_id='00006-1' and  rownum=1 order by process_id desc )
      

  3.   

    update ws_bffaultsheet_iprocess s set s.attachment_id = 521
    where s.old_sheet_id='00006-1' and not exists(select 1 from ws_bffaultsheet_iprocess t where t.process_id >s.process_id );
    试试看?
      

  4.   

    楼上的查询报错啊,order by process_id desc 前面说缺少右括号
      

  5.   

    update ws_bffaultsheet_iprocess s
       set s.attachment_id = 521
     where process_id = (select max(process_id)
                           from ws_bffaultsheet_iprocess
                          where old_sheet_id = '00006-1')
      

  6.   

    update sheet_iprocess a set a.attachment_id='521' where process_id=(select max(b.process_id) where b.sheet_id='00006-1'  )   这样怎么样
      

  7.   


    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'  ) 
      

  8.   

    select max(b.process_id) where b.sheet_id='00006-1'
      

  9.   

    楼主试试这个呢:
    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'