8000 Update README.md · Learner457/sql-50-leetcode@504e0bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 504e0bd

Browse files
authored
Update README.md
1 parent 9eddb78 commit 504e0bd

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,20 @@ ON s.product_id = p.product_id
6060

6161
[1581 - Customer Who Visited but Did Not Make Any Transactions](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions/)
6262
```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;
6777
```
6878

6979
[197 - Rising Temperature](https://leetcode.com/problems/rising-temperature/)

0 commit comments

Comments
 (0)
0