请大家帮我转化下这个语句 转成exists 和 NOT exits格式的
select count(distinct mfg_no) from pda_mugn_mobile where mmcd='E202' and mfg_no in (select mfg_no from mfs_maintain where substr(maintain_code,0,1) not in ('6','5','8'));

解决方案 »

  1.   

    select count(distinct mfg_no) from pda_mugn_mobile where mmcd='E202' and mfg_no exists (select mfg_no from mfs_maintain where substr(maintain_code,0,1) not exists ('6','5','8'));
      

  2.   

    tryselect count(distinct mfg_no) from pda_mugn_mobile where mmcd='E202' and exists (select 1 from mfs_maintain where pda_mugn_mobile.mfg_no = mfs_maintain.mfg_no and substr(maintain_code,0,1) not in ('6','5','8'));
      

  3.   

    最后的NOT IN  能改成NOT EXISTS的吗?
      

  4.   

    最后一个改不改没什么价值啊。实在要改可以改成
    select count(distinct mfg_no) from pda_mugn_mobile  where mmcd='E202' and exists (select 1 from mfs_maintain where pda_mugn_mobile.mfg_no = mfs_maintain.mfg_no and not exists(select 1 from dual where substr(pda_mugn_mobile.maintain_code,0,1)=5 or substr(pda_mugn_mobile.maintain_code,0,1)=6 or substr(pda_mugn_mobile.maintain_code,0,1)=8);
      

  5.   

    后面的觉得怪怪的。而且maintain_code是在MFS_MAINTAIN中的。我原意是select mfg_no from mfs_maintain where substr(maintain_code,0,1) not in ('6','5','8') 在mfs_maintain中找出 不等于 5 6 8 开头的数
      

  6.   

    我写错了,原来没看明白,改正后如下
    select count(distinct mfg_no) from pda_mugn_mobile where mmcd='E202' and exists (select 1 from mfs_maintain where pda_mugn_mobile.mfg_no = mfs_maintain.mfg_no and  not exists(select 1 from dual where  substr(mfs_maintain.maintain_code,0,1)='5' or substr(mfs_maintain.maintain_code,0,1)='6' or substr(mfs_maintain.maintain_code,0,1)='8'));
      

  7.   

    select count(distinct mfg_no)
    from pda_mugn_mobile,(select mfg_no from mfs_maintain where not regexp_like(maintain_code,'^[568]') B
    where mmcd='E202' and pda_mugn_mobile.mfg_no = B.mfg_no;