日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

not in SQL语句转化为 not exists

發(fā)布時(shí)間:2024/9/20 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 not in SQL语句转化为 not exists 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

not in 語(yǔ)句效率比not exists 效率要低.在對(duì)sql執(zhí)行效率要求比較高的情況下,需要把not in 語(yǔ)句轉(zhuǎn)化為not exists.

有數(shù)據(jù)表如下圖:

現(xiàn)在需要找出在ParentMissionID列中存在但在MissionID列中不存在的數(shù)字.

用not in 語(yǔ)句很容易實(shí)現(xiàn):

  • select?p.[ParentMissionID]?from?
  • ?
  • ??(select?[ParentMissionID]?FROM?[Test].[dbo].[TestMissionParent]?where?projectId=1)?as?p?
  • ?
  • ???where?p.[ParentMissionID]?not?in?(select?[MissionID]?FROM?[Test].[dbo].[TestMissionParent]?where?projectId=1)?
  • 用not exists 語(yǔ)句則為:

  • SELECT?[ParentMissionID]?
  • FROM?(SELECT?[ParentMissionID]?
  • ??????FROM?[Test].[dbo].[TestMissionParent]?
  • ??????where?projectID=1)?as?p?where?not?exists?
  • ??????(select?1?from?(select?missionId?from?[Test].[dbo].[TestMissionParent]?where?projectId=1)?as?m?where?m.missionId=p.parentMissionId)??
  • 其他情況可以根據(jù)這個(gè)規(guī)律自行改造.

    轉(zhuǎn)載于:https://blog.51cto.com/siqiutong/1093097

    總結(jié)

    以上是生活随笔為你收集整理的not in SQL语句转化为 not exists的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。