🤔 문제 분석
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
'코딩테스트 > 리트코드 SQL' 카테고리의 다른 글
[리트코드/SQL] 18. Rising Temperature (197) (0) | 2022.12.18 |
---|---|
[리트코드/SQL] 17. Article Views I (1148) (0) | 2022.12.18 |
[리트코드/SQL] 15. Combine Two Tables (175) (0) | 2022.12.18 |
[리트코드/SQL] 14. Second Highest Salary (176) (0) | 2022.12.16 |
[리트코드/SQL] 13. Tree node (608) (0) | 2022.12.16 |
댓글