gpt4 book ai didi

sql-server - 将一个表的数据与另一个表的数据进行比较的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-03 17:54:23 25 4
gpt4 key购买 nike

我有 2 个选择语句:

SELECT DISTINCT Email
FROM dbo.Customers
WHERE (Email IS NOT NULL)
AND (Email LIKE '%@%')
AND (RIGHT(Email, 4) IN ('.net', '.com', '.org'))
AND (Email NOT LIKE '%@UniformCity.com')
AND (Email NOT LIKE '%@LifeUniform.com')
AND (CHARINDEX('.',Email) <> 1)
AND (RIGHT(RTRIM(Email), 1) <> '.') AND (LEFT(LTRIM(Email), 1) <> '@')
AND (Email not Like '%[`:;_*-,^[^]()+%\/=#-]%' escape '^') order by Email

SELECT  replace(replace(
replace(
replace(EmailOptOut,'"','')
, ',held','')
, ',unsub','')
, ',confirm','')
as CleanEmail
FROM [LifeMail].[dbo].[EmailOptOuts]

我只想从 Customers 表中选择电子邮件,它们不在 EmailOptOuts 表中。实现这一目标的最佳方法是什么?我考虑过使用游标和循环......

最佳答案

我打算将这些表放入临时表中,但如果需要,您可以组合查询。

SELECT DISTINCT Email
INTO #tCustomersEmail
FROM dbo.Customers
WHERE ( Email IS NOT NULL )
AND ( Email LIKE '%@%' )
AND ( RIGHT(Email, 4) IN ( '.net', '.com', '.org' ) )
AND ( Email NOT LIKE '%@UniformCity.com' )
AND ( Email NOT LIKE '%@LifeUniform.com' )
AND ( CHARINDEX('.', Email) <> 1 )
AND ( RIGHT(RTRIM(Email), 1) <> '.' )
AND ( LEFT(LTRIM(Email), 1) <> '@' )
AND ( Email NOT LIKE '%[`:;_*-,^[^]()+%\/=#-]%' ESCAPE '^' )
ORDER BY Email

SELECT REPLACE(REPLACE(REPLACE(REPLACE(EmailOptOut, '"', ''), ',held', ''),',unsub', ''), ',confirm', '') AS CleanEmail
INTO #tOptOuts
FROM [LifeMail].[dbo].[EmailOptOuts]

SELECT Email
FROM #tCustomersEmail AS tce
WHERE Email NOT IN (SELECT CleanEmail FROM #tOptOuts AS too)

关于sql-server - 将一个表的数据与另一个表的数据进行比较的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8068407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com