Skip to content

Commit 42ca82c

Browse files
authored
Add files via upload
1 parent 173bc69 commit 42ca82c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

EASY/1083 - Sales Analysis II.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
create table Product_1083(product_id int, product_name varchar(10), unit_price double);
2+
insert into Product_1083(product_id, product_name, unit_price) values(1, 'S8', 1000), (2, 'G4', 800), (3, 'iphone', 1400);
3+
4+
create table Sales_1083(seller_id int, product_id int, buyer_id int, sale_date date, quantity int, price double);
5+
insert into Sales_1083(seller_id, product_id, buyer_id, sale_date, quantity, price) values(1, 1, 1, '2019-01-21', 2, 2000), (1, 2, 2, '2019-02-17', 1, 800), (2, 1, 3, '2019-06-02', 1, 800), (3, 3, 3, '2019-05-13', 2, 2800);
6+
7+
with cte as (select s.*, p.product_name
8+
from Product_1083 p join Sales_1083 s
9+
on p.product_id=s.product_id)
10+
11+
select distinct buyer_id from cte where product_name='S8'
12+
and buyer_id not in (select distinct buyer_id from cte where product_name='iphone');

0 commit comments

Comments
 (0)