所以我在not in子句中有大量值需要一段时间才能执行。在SQL Server中有更好的方法吗?
SELECT A.invid AS InventoryID,
A.VIN
FROM autoinventory A
WHERE A.invId NOT IN ('{001A2AA7-B9EF-4152-B1CB-92DFD520FB31}', '{011FE0A7-AA5E-43F7-B485-08EC0427643F}', '{0496CE3E-664D-4762-ACE4-A7A7225A9FF5}', '{077505EF-0641-4B14-94D4-93F9C18EAB67}', '{1757DF73-CAAB-4889-AF98-EB139514F108}', '{17D7C6DE-8039-4143-BB2A-B1A6D1AE7728}', '{19304107-75EF-41AB-9C25-BBF3B41227B3}', '{1E231903-3C06-4E4A-A8DA-675B2A28233F}', '{205F042D-774B-4125-815B-7379F335054B}', '{27D8CA29-4973-465B-A7AF-4BBA5B31FAD0}', '{2873542F-B70F-4D07-A914-CE3174A07208}', '{2B0869EB-9D68-4C6C-827A-72D09152B805}', '{2DCCEDA5-F155-4E6F-A838-AA5488268E8E}', '{3E3D5104-1B0A-4887-B990-398E5A752DD3}', '{42B45A1A-2F6E-4673-B303-05A3B30E48FF}', '{42BD4E87-D32B-49AB-A0EF-BC7504291DFC}', '{46B68F19-9D70-4938-9451-4B2AF8D05C69}', '{47650339-ECF0-444A-B753-285ED48B9D7E}', '{47921239-4D77-4669-9592-4F2FAFE9F4F6}', '{4A50FDC6-09C1-4396-9B32-368D7501E02E}', '{526FA03E-B9DE-4D06-ADAE-02AB751EBCEB}', '{527325BA-BDD3-43A5-B9B2-20740D193E5D}', '{53CCDCF0-3EDA-46ED-8584-8114DB7286CD}', '{544A4432-C68A-4EAF-985C-42AABAB917F0}', '{565629E6-56ED-4770-B2C4-A7C428EEC920}', '{56A82C0F-A8C6-46AB-B6A5-65FF8F5D85F3}', '{58A56A88-3D13-4508-BBB0-BD39BE7B7E5E}', '{58C30254-3401-4C9C-A73F-2C1F880611D2}', '{5ACE9BDD-7EEC-4757-A88A-37AD7DAAC275}', '{5B8950D8-5A0D-4CB4-8A06-826CEB907B1B}', '{5C48CD52-9288-4560-9E36-8AFF6D8D8522}', '{61C7983F-59B6-449F-BEC8-B9D04111E1DA}', '{63750381-C99A-449B-BA5D-C8AEAAC35F6F}', '{63E5B6D8-C684-4CB7-9D40-9B1EC4F33A6C}', '{6477667B-E27B-4FC9-B800-5BD08D76A63C}', '{6A7DE56C-6305-45E0-AF9B-C1337FE0E453}', '{6BD311D2-9810-4ACF-BCB2-DCA89D19BC35}', '{6BEF68E5-95A8-41F8-9C3A-17F6583C8BD7}', '{6C3EB9F8-64F3-4BA0-873E-DCFEF48ED599}', '{76804EFE-4E70-426F-AAE7-7C52C0B8BD76}', '{833B7C7E-BE2B-4C34-ADE3-29AE2647F4E0}', '{86C5FCDD-845B-4435-BE80-19E38D291B1A}', '{876282B5-7F54-4D2A-823C-0F894DDE5129}', '{87B20AA9-8958-4580-8BB7-70B4C5A24A9C}', '{895BE060-2AA2-1D4F-AC97-E16138E8A70D}', '{8B1B3237-7048-4D61-9D9F-C85643B5B151}', '{8D6FBC0E-918B-428D-9F66-572FC3F40492}', '{934AF74F-8F40-413B-AC5D-4DF35F9A573F}', '{953C1B7A-CEAD-4A4C-85F9-5DA6846AE762}', '{97777F76-3DF6-477E-B236-F9B790B1BC76}', '{9B09151D-A549-466E-9ACE-02AD98C0A37F}', '{A1D0C29C-E598-4909-8E15-BFBD7A56DD2D}', '{A22BBDA3-9965-48DF-99D8-7FF90D93894D}', '{A447BB9E-F871-4F75-8EEC-9FD10241FB2A}', '{B3EF2031-D65D-42B6-ACC3-9AD3AA38355B}', '{B4D19CFA-1D7E-44A7-9676-3BB08603964E}', '{B5664B91-5A89-4A3D-966E-3C77E59949FA}', '{B6CA3712-17F8-4CDA-AC82-9E084F7C6000}', '{C15B05E4-988C-4FDE-A87B-53D87D81A2B2}', '{C4010048-E365-4A14-9C49-CDD7940A418D}', '{C937DAC8-DEEB-41A3-8F42-D287270F45FA}', '{CB9BB094-7262-4084-BABD-6F63B3639445}', '{D4B23B3C-305D-443E-AD52-EADEB1DFC234}', '{D6645333-B4FE-4F45-9577-ED6B0407A273}', '{D66B4575-31E7-4CCD-8AC0-42B1190DA7B3}', '{D73BFEFC-1F96-4F19-A441-ECB7E4D95628}', '{D7B73452-C1DE-4974-A560-8FA5E33975CE}', '{D9B3363A-13FE-424F-932D-9DF68242FFA6}', '{DBC50CAE-448E-4FF1-8E08-51C80803F1BD}', '{DC495069-D7A4-473B-9210-B098496D8FA8}', '{DCF5C85A-8930-4B80-8EA6-05FC3FC5B9C0}', '{DD2BE546-4A36-4E2A-BCBC-425666DFCCDB}', '{DE8AD8BE-6062-4303-A066-164D9516D392}', '{E3E6936E-2510-4B78-9DB4-956F3132EA38}', '{E7513BF8-D848-404B-805B-0AC253C5B283}', '{E8DEF1FF-ADD1-4206-B3BD-797D190EC62B}', '{E8F6F694-E8C3-48F7-B946-7CA202DBC002}', '{EB5B3C2E-1056-4765-A468-7B2BF72CC9F1}', '{FBF3A887-A26E-4590-BD28-7F461F2E532A}')
答案 0 :(得分:1)
如果没有表格大小的数量,我无法确定这会更有效率,但我发现通常不存在通常比不存在更快且速度更快。
SELECT A.invid AS InventoryID,
A.VIN
FROM autoinventory A
WHERE NOT EXISTS (SELECT 1
FROM AutoInventory B
WHERE A.INVID = B.InvID
and A.invId IN ('{001A2AA7-B9EF-4152-B1CB-92DFD520FB31}', '{011FE0A7-AA5E-43F7-B485-08EC0427643F}', '{0496CE3E-664D-4762-ACE4-A7A7225A9FF5}', '{077505EF-0641-4B14-94D4-93F9C18EAB67}', '{1757DF73-CAAB-4889-AF98-EB139514F108}', '{17D7C6DE-8039-4143-BB2A-B1A6D1AE7728}', '{19304107-75EF-41AB-9C25-BBF3B41227B3}', '{1E231903-3C06-4E4A-A8DA-675B2A28233F}', '{205F042D-774B-4125-815B-7379F335054B}', '{27D8CA29-4973-465B-A7AF-4BBA5B31FAD0}', '{2873542F-B70F-4D07-A914-CE3174A07208}', '{2B0869EB-9D68-4C6C-827A-72D09152B805}', '{2DCCEDA5-F155-4E6F-A838-AA5488268E8E}', '{3E3D5104-1B0A-4887-B990-398E5A752DD3}', '{42B45A1A-2F6E-4673-B303-05A3B30E48FF}', '{42BD4E87-D32B-49AB-A0EF-BC7504291DFC}', '{46B68F19-9D70-4938-9451-4B2AF8D05C69}', '{47650339-ECF0-444A-B753-285ED48B9D7E}', '{47921239-4D77-4669-9592-4F2FAFE9F4F6}', '{4A50FDC6-09C1-4396-9B32-368D7501E02E}', '{526FA03E-B9DE-4D06-ADAE-02AB751EBCEB}', '{527325BA-BDD3-43A5-B9B2-20740D193E5D}', '{53CCDCF0-3EDA-46ED-8584-8114DB7286CD}', '{544A4432-C68A-4EAF-985C-42AABAB917F0}', '{565629E6-56ED-4770-B2C4-A7C428EEC920}', '{56A82C0F-A8C6-46AB-B6A5-65FF8F5D85F3}', '{58A56A88-3D13-4508-BBB0-BD39BE7B7E5E}', '{58C30254-3401-4C9C-A73F-2C1F880611D2}', '{5ACE9BDD-7EEC-4757-A88A-37AD7DAAC275}', '{5B8950D8-5A0D-4CB4-8A06-826CEB907B1B}', '{5C48CD52-9288-4560-9E36-8AFF6D8D8522}', '{61C7983F-59B6-449F-BEC8-B9D04111E1DA}', '{63750381-C99A-449B-BA5D-C8AEAAC35F6F}', '{63E5B6D8-C684-4CB7-9D40-9B1EC4F33A6C}', '{6477667B-E27B-4FC9-B800-5BD08D76A63C}', '{6A7DE56C-6305-45E0-AF9B-C1337FE0E453}', '{6BD311D2-9810-4ACF-BCB2-DCA89D19BC35}', '{6BEF68E5-95A8-41F8-9C3A-17F6583C8BD7}', '{6C3EB9F8-64F3-4BA0-873E-DCFEF48ED599}', '{76804EFE-4E70-426F-AAE7-7C52C0B8BD76}', '{833B7C7E-BE2B-4C34-ADE3-29AE2647F4E0}', '{86C5FCDD-845B-4435-BE80-19E38D291B1A}', '{876282B5-7F54-4D2A-823C-0F894DDE5129}', '{87B20AA9-8958-4580-8BB7-70B4C5A24A9C}', '{895BE060-2AA2-1D4F-AC97-E16138E8A70D}', '{8B1B3237-7048-4D61-9D9F-C85643B5B151}', '{8D6FBC0E-918B-428D-9F66-572FC3F40492}', '{934AF74F-8F40-413B-AC5D-4DF35F9A573F}', '{953C1B7A-CEAD-4A4C-85F9-5DA6846AE762}', '{97777F76-3DF6-477E-B236-F9B790B1BC76}', '{9B09151D-A549-466E-9ACE-02AD98C0A37F}', '{A1D0C29C-E598-4909-8E15-BFBD7A56DD2D}', '{A22BBDA3-9965-48DF-99D8-7FF90D93894D}', '{A447BB9E-F871-4F75-8EEC-9FD10241FB2A}', '{B3EF2031-D65D-42B6-ACC3-9AD3AA38355B}', '{B4D19CFA-1D7E-44A7-9676-3BB08603964E}', '{B5664B91-5A89-4A3D-966E-3C77E59949FA}', '{B6CA3712-17F8-4CDA-AC82-9E084F7C6000}', '{C15B05E4-988C-4FDE-A87B-53D87D81A2B2}', '{C4010048-E365-4A14-9C49-CDD7940A418D}', '{C937DAC8-DEEB-41A3-8F42-D287270F45FA}', '{CB9BB094-7262-4084-BABD-6F63B3639445}', '{D4B23B3C-305D-443E-AD52-EADEB1DFC234}', '{D6645333-B4FE-4F45-9577-ED6B0407A273}', '{D66B4575-31E7-4CCD-8AC0-42B1190DA7B3}', '{D73BFEFC-1F96-4F19-A441-ECB7E4D95628}', '{D7B73452-C1DE-4974-A560-8FA5E33975CE}', '{D9B3363A-13FE-424F-932D-9DF68242FFA6}', '{DBC50CAE-448E-4FF1-8E08-51C80803F1BD}', '{DC495069-D7A4-473B-9210-B098496D8FA8}', '{DCF5C85A-8930-4B80-8EA6-05FC3FC5B9C0}', '{DD2BE546-4A36-4E2A-BCBC-425666DFCCDB}', '{DE8AD8BE-6062-4303-A066-164D9516D392}', '{E3E6936E-2510-4B78-9DB4-956F3132EA38}', '{E7513BF8-D848-404B-805B-0AC253C5B283}', '{E8DEF1FF-ADD1-4206-B3BD-797D190EC62B}', '{E8F6F694-E8C3-48F7-B946-7CA202DBC002}', '{EB5B3C2E-1056-4765-A468-7B2BF72CC9F1}', '{FBF3A887-A26E-4590-BD28-7F461F2E532A}')