# 1581. Customer Who Visited but Did Not Make Any Transactions [leetcode](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/?envType=study-plan-v2&envId=top-sql-50) ![image](https://hackmd.io/_uploads/rkXwk-jp6.png) ![image](https://hackmd.io/_uploads/rJTPkWj6a.png) 這一題要問 拜訪過的顧客 卻沒有購買的人+次數 所以我們需要用到left join 因為需要找沒有購買紀錄的 所以購買紀錄必須要是null ``` WHERE a2.transaction_id IS NULL ``` 然後依照a1.顧客來判斷 誰拜訪後卻沒有購買 ```SQL # Write your MySQL query statement below SELECT a1.customer_id ,COUNT(a1.visit_id) as count_no_trans FROM Visits a1 LEFT JOIN Transactions a2 ON a1.visit_id = a2.visit_id WHERE a2.transaction_id IS NULL GROUP BY a1.customer_id; ```