Skip to content

Commit 76a4d57

Browse files
authored
Update Sales Analysis 2.sql
1 parent a9829f2 commit 76a4d57

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Easy/Sales Analysis 2.sql

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,27 @@ on a.product_id = b.product_id
6464
where a.buyer_id in
6565
(Select a.buyer_id from sales a join product b on a.product_id = b.product_id where b.product_name = 'S8')
6666
and
67-
a.buyer_id not in (Select a.buyer_id from sales a join product b on a.product_id = b.product_id where b.product_name = 'iPhone')
67+
a.buyer_id not in (Select a.buyer_id from sales a join product b on a.product_id = b.product_id where b.product_name = 'iPhone')
68+
69+
70+
71+
My sol:
72+
73+
with cte as (
74+
select
75+
buyer_id,
76+
iphone = sum(case when product_name = 'iPhone' then 1 else 0 end),
77+
s8 = sum(case when product_name = 'S8' then 1 else 0 end)
78+
from Sales s inner join Product p on s.product_id = p.product_id
79+
group by buyer_id
80+
)
81+
select buyer_id from cte
82+
where iphone = 0 and s8 >= 1
83+
84+
85+
86+
87+
88+
89+
90+

0 commit comments

Comments
 (0)