#82. [LeetCode / MySQL] 1581. Customer Who Visited but Did Not Make Any Transactions

문제

 

입력 코드

1. 

SELECT V.customer_id, COUNT(V.visit_id) AS count_no_trans
FROM Visits AS V
    LEFT JOIN Transactions AS T
    ON V.visit_id = T.visit_id
WHERE T.transaction_id IS NULL
GROUP BY V.customer_id

 

2. 

SELECT customer_id, COUNT(visit_id) AS count_no_trans 
FROM Visits 
WHERE visit_id NOT IN(
    SELECT DISTINCT visit_id 
    FROM Transactions
    ) 
GROUP BY customer_id

 

코드 설명

#SELECT #COUNT #LEFT JOIN #JOIN #NULL #GROUP BY #NOT IN #DISTINCT

 

 

문제 출처

 

Customer Who Visited but Did Not Make Any Transactions - LeetCode

Can you solve this real interview question? Customer Who Visited but Did Not Make Any Transactions - Table: Visits +-------------+---------+ | Column Name | Type | +-------------+---------+ | visit_id | int | | customer_id | int | +-------------+---------+

leetcode.com