ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 提高SQL执行效率(一):把 IN换为 EXISTS

提高SQL执行效率(一):把 IN换为 EXISTS

原创 Linux操作系统 作者:jarli 时间:2019-05-29 16:21:04 0 删除 编辑
提高SQL执行效率(一):把 IN换为 EXISTS

修改前SQL:

SELECT WDJ.ORGANIZATION_ID,
WDJ.WIP_ENTITY_ID,
WE.WIP_ENTITY_NAME,
WDJ.START_QUANTITY,
WDJ.STATUS_TYPE,
WDJ.SCHEDULED_START_DATE,
WDJ.SCHEDULED_COMPLETION_DATE
FROM WIP_DISCRETE_JOBS WDJ,
WIP_ENTITIES WE
WHERE WDJ.STATUS_TYPE IN (3, 6)
AND WDJ.WIP_ENTITY_ID=WE.WIP_ENTITY_ID
AND WDJ.ORGANIZATION_ID=WE.ORGANIZATION_ID
AND (WDJ.ORGANIZATION_ID, WDJ.WIP_ENTITY_ID) NOT IN ( SELECT ORGANIZATION_ID,
WIP_ENTITY_ID
FROM CUX_WIP_EXCEPTION_INFO)

修改后SQL:

SELECT WDJ.ORGANIZATION_ID,
WDJ.WIP_ENTITY_ID,
WE.WIP_ENTITY_NAME,
WDJ.START_QUANTITY,
WDJ.STATUS_TYPE,
WDJ.SCHEDULED_START_DATE,
WDJ.SCHEDULED_COMPLETION_DATE
FROM WIP_DISCRETE_JOBS WDJ,
WIP_ENTITIES WE
WHERE WDJ.STATUS_TYPE IN (3, 6)
AND WDJ.WIP_ENTITY_ID=WE.WIP_ENTITY_ID
AND WDJ.ORGANIZATION_ID=WE.ORGANIZATION_ID
AND NOT EXISTS (SELECT 1
FROM CUX_WIP_EXCEPTION_INFO CI
WHERE CI.ORGANIZATION_ID = WDJ.ORGANIZATION_ID
AND CI.WIP_ENTITY_ID = WDJ.WIP_ENTITY_ID) ;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/41594/viewspace-50555/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2003-03-27

  • 博文量
    227
  • 访问量
    162763