update mom20100
set finished='1'
from (
select top 100 PERCENT refno,mom30100.type,mom30100.refseq, mom20100.gxh from mom30100,mom30101 ,mom20100
where mom30100.type<>'1' and mom30100.no = mom30101.no and mom30101.no>=@s_no and 
mom30101.no<=@e_no and mom30100.refno = mom20100.momno and mom30100.refseq = mom20100.seq and mom30100.type = mom20100.type and mom30100.gxh= mom20100.gxh
group by mom30100.type,refno,mom30100.refseq,mom20100.num, mom20100.gxh
having sum(mom30101.num)>=mom20100.num
order by mom30100.type,refno,mom30100.refseq, mom20100.gxh)t
where t.refno = mom20100.momno and t.type = mom20100.type and t.refseq = mom20100.seq and finished='0' and t.gxh= mom20100.gxh以上语句在ORACLE中如何实现 

解决方案 »

  1.   

    delete mom20100
    from mom10100
    where mom20100.momno = mom10100.no and mom20100.type = '2' and mom10100.ifzc='0' and mom10100.finished='1'这个如何实现
      

  2.   


    delete mom20100
    where exists(select 1 from mom10100
    where mom20100.momno = mom10100.no and mom20100.type = '2' and mom10100.ifzc='0' and mom10100.finished='1')
      

  3.   


    with t as (
    select refno,mom30100.type,mom30100.refseq, mom20100.gxh
    from mom30100,mom30101 ,mom20100
    where mom30100.type<>'1' and mom30100.no = mom30101.no 
    and mom30101.no>=&s_no and mom30101.no<=&e_no 
    and mom30100.refno = mom20100.momno 
    and mom30100.refseq = mom20100.seq 
    and mom30100.type = mom20100.type and mom30100.gxh= mom20100.gxh
    group by mom30100.type,refno,mom30100.refseq,mom20100.num, mom20100.gxh
    having sum(mom30101.num)>=mom20100.num
    )
    update (select mom20100.* from t, mom20100 
    where t.refno = mom20100.momno and t.type = mom20100.type
    and t.refseq = mom20100.seq and finished='0' and t.gxh= mom20100.gxh) m
    set m.finished='1';
      

  4.   

    4楼的 你的语句跟建立临时表应该是差不多一样的吧 如果建立临时表 我也大体知道
    str = 'create table  t as 
    select top 100 PERCENT refno,mom30100.type,mom30100.refseq, mom20100.gxh from mom30100,mom30101 ,mom20100
    where mom30100.type<>'1' and mom30100.no = mom30101.no and mom30101.no>=@s_no and  
    mom30101.no<=@e_no and mom30100.refno = mom20100.momno and mom30100.refseq = mom20100.seq and mom30100.type = mom20100.type and mom30100.gxh= mom20100.gxh
    group by mom30100.type,refno,mom30100.refseq,mom20100.num, mom20100.gxh
    having sum(mom30101.num)>=mom20100.num
    order by mom30100.type,refno,mom30100.refseq, mom20100.gxh'
    execute immediate str;
     
      

  5.   

    回答5楼的问题 
    delete mom20100
    from mom10100
    where mom20100.momno = mom10100.no and mom20100.type = '2' and mom10100.ifzc='0' and mom10100.finished='1'虽然我也好久不用SQL SERVER 2000了 不过用的时间还比较长 我想问下 这个语句是从MOM20100中删除数据吗 这个我还真记不清了 我理解应该是从MOM10100中吧
      

  6.   

    回复4楼的 你的语句 如何实现的select top 100 PERCENT 这个是查询结果集%100的意思 如果我想实现
    select top 15 percent 这个呢
      

  7.   

    应该与“可更新视图”类似。with a as (
    select refno,mom30100.type,mom30100.refseq, mom20100.gxh
    from mom30100,mom30101 ,mom20100
    where mom30100.type<>'1' and mom30100.no = mom30101.no 
    and mom30101.no>=&s_no and mom30101.no<=&e_no 
    and mom30100.refno = mom20100.momno 
    and mom30100.refseq = mom20100.seq 
    and mom30100.type = mom20100.type and mom30100.gxh= mom20100.gxh
    group by mom30100.type,refno,mom30100.refseq,mom20100.num, mom20100.gxh
    having sum(mom30101.num)>=mom20100.num
    order by mom30100.type,refno,mom30100.refseq, mom20100.gxh
    ),
    t as(
    select * from t where rownum/(select count(*) from t)<=0.15
    )
    update (select mom20100.* from t, mom20100 
    where t.refno = mom20100.momno and t.type = mom20100.type
    and t.refseq = mom20100.seq and finished='0' and t.gxh= mom20100.gxh) m
    set m.finished='1';
      

  8.   

    如何这么写 行不行 会不会有什么问题update mom20100
    set finished='1'
    where exists (select 1 from (
    select top 100 PERCENT refno,mom30100.type,mom30100.refseq, mom20100.gxh from mom30100,mom30101 ,mom20100
    where mom30100.type<>'1' and mom30100.no = mom30101.no and mom30101.no>=@s_no and  
    mom30101.no<=@e_no and mom30100.refno = mom20100.momno and mom30100.refseq = mom20100.seq and mom30100.type = mom20100.type and mom30100.gxh= mom20100.gxh
    group by mom30100.type,refno,mom30100.refseq,mom20100.num, mom20100.gxh
    having sum(mom30101.num)>=mom20100.num
    order by mom30100.type,refno,mom30100.refseq, mom20100.gxh)t
    where t.refno = mom20100.momno and t.type = mom20100.type and t.refseq = mom20100.seq and finished='0' and t.gxh= mom20100.gxh);