Snoopy [리트코드/SQL] 16. Customer Who Visited but Did Not Make Any Transactions (1581)
코딩테스트/리트코드 SQL

[리트코드/SQL] 16. Customer Who Visited but Did Not Make Any Transactions (1581)

Sooyoon Jeong 2022. 12. 18.

🤔 문제 분석

1) Write an SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.

2) Return the result table sorted in any order.

 

💡 풀이

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

 

댓글