1
我有一個表TransactionData
,其中包含客戶的交易數據,另一個表Subscribers
包含的客戶是通訊訂戶。SQL Server:與從未在線購買的客戶聯繫
這是我需要做的:從TransactionData
表中選擇也在Subscribers
表中並且從未在線購買產品(StoreID = 50001
)的所有訂戶。
這兩個表的唯一鍵是客戶的電子郵件地址。
這是基本的表結構。
TransactionData
Email StoreID OrderID
[email protected] 50001 101
[email protected] 50001 102
[email protected] 50001 201
[email protected] 51111 202
[email protected] 50001 301
[email protected] 50001 302
認購
Email
[email protected]
[email protected]
期望的結果
Email StoreID
[email protected] 51111
這是我的查詢到目前爲止:
SELECT
b.Email, b.BoutiqueId
FROM
HasNewsletterPermission2014 AS a
INNER JOIN
TransactionData AS b ON a.Email = b.Email
WHERE
b.BoutiqueId <> 50001
我不知道如何排除從未在線購買的客戶。
你能幫我嗎?
根據您的要求,查詢應返回NO ROWS – Eralper
或者只是將您的INNER連接更改爲LEFT連接並添加where謂詞「其中b.Email IS NULL」 –
示例和說明不等效,區別作爲您的榜樣,在交易不是在線訂單的情況下會產生客戶,並且描述/請求適用於從未有過在線訂單的客戶。 – rwking