File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -64,4 +64,27 @@ on a.product_id = b.product_id
64
64
where a .buyer_id in
65
65
(Select a .buyer_id from sales a join product b on a .product_id = b .product_id where b .product_name = ' S8' )
66
66
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
+
You can’t perform that action at this time.
0 commit comments