有没有更好的方法来写这个?首先,我指的是THEN
语句,基本上重复了CASE WHEN EXISTS
语句。最好在SELECT DateJoined
语句内使用EXISTS
,然后在THEN
的该语句外使用它。有可能吗?
SELECT
Email,
CASE
WHEN EXISTS (SELECT 1
FROM _Subscribers
WHERE EmailAddress = Email)
THEN (SELECT DateJoined
FROM _Subscribers
WHERE EmailAddress = Email)
ELSE LastModifiedDate
END as CreatedDate
FROM
[Optin Monster]
答案 0 :(得分:0)
感谢@Lamak在此方面的帮助。这成功了。
SELECT
om. Email,
CASE WHEN s.DateJoined <> '' OR s.DateJoined IS NOT NULL
THEN s.DateJoined
ELSE LastModifiedDate
END as CreatedDate
FROM [Optin Monster] om
LEFT JOIN _Subscribers s
ON om.Email = s.EmailAddress