## 1082. Sales Analysis I

Question:

Solution:

``````select
seller_id
from (
select
seller_id,
rank() over (order by price desc) r
from (
select
s.seller_id,
sum(s.price) as price
from Sales s
group by 1
) a
) b
where r = 1
order by 1``````

## 1083. Sales Analysis II

Question:

Solution:

``````select distinct
from (
select
case
select distinct
from Sales s
join Product p
on s.product_id = p.product_id
where product_name = 'iPhone'
) then 1
else 0
case
select distinct
from Sales s
join Product p
on s.product_id = p.product_id
where product_name = 'S8'
) then 1
else 0
from Sales
) a

## 1084. Sales Analysis III

Question:

Solution:

``````select distinct
a.product_id,
a.product_name
from(
select distinct
s.product_id,
p.product_name,
min(s.sale_date) as min_sale_date,
max(s.sale_date) as max_sale_date
from Sales s
left join Product p
on s.product_id = p.product_id
where quantity >=1
group by 1,2
) a
where (
a.min_sale_date >= '2019-01-01'
and a.min_sale_date <= '2019-03-31'
)
and (
a.max_sale_date >= '2019-01-01'
and a.max_sale_date <= '2019-03-31'
)``````