Jacobvu84 / sql-basic-advance

SQL
0 stars 0 forks source link

Shopping window #5

Open Jacobvu84 opened 9 months ago

Jacobvu84 commented 9 months ago

image

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
Jacobvu84 commented 9 months ago
select 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 customer_id
Jacobvu84 commented 9 months ago
SELECT customer_id, COUNT(visit_id) as count_no_trans 
FROM Visits v
WHERE NOT EXISTS (
    SELECT visit_id FROM Transactions t 
    WHERE t.visit_id = v.visit_id
    )
GROUP BY customer_id