File tree 1 file changed +14
-4
lines changed 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,20 @@ ON s.product_id = p.product_id
60
60
61
61
[ 1581 - Customer Who Visited but Did Not Make Any Transactions] ( https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/ )
62
62
``` sql
63
- SELECT customer_id, COUNT (* ) as count_no_trans
64
- FROM Visits
65
- WHERE visit_id NOT IN (SELECT DISTINCT visit_id FROM Transactions)
66
- GROUP BY customer_id
63
+ select v .customer_id , count (v .visit_id ) as count_no_trans
64
+ from Visits v
65
+ left join Transactions t
66
+ On v .visit_id = t .visit_id
67
+ Where t .transaction_id is Null
68
+ group by v .customer_id ;
69
+
70
+ -- 2nd approach: using Subquery (This approach is not ideal as this problem can be solved using joins)
71
+ SELECT customer_id, COUNT (visit_id) as count_no_trans
72
+ FROM Visits
73
+ WHERE visit_id NOT IN (
74
+ SELECT visit_id FROM Transactions
75
+ )
76
+ GROUP BY customer_id;
67
77
```
68
78
69
79
[ 197 - Rising Temperature] ( https://leetcode.com/problems/rising-temperature/ )
You can’t perform that action at this time.
0 commit comments