1082. 销售分析 I
【暂定:一个表用到rank函数用group by,两表以上在over用partition by
另外rank()over()内部要有排名的规则:rank()over(order by sum(price) desc) weici
中规则是薪水之和降序】
【两表问题无法直接解决可以考虑连接】
select seller_id
from(
select seller_id ,
rank()over(order by sum(price) desc) weici
from Sales
group by seller_id
)new_table
where weici=1
1083. 销售分析 II
# Write your MySQL query statement below
select distinct buyer_id
from Sales
where buyer_id in(
#先找出买S8的人
select buyer_id
from Sales
where product_id = (select product_id from Product where product_name ='S8'))
and buyer_id not in(
#在找出没有买iPhone的人
select buyer_id
from Sales
where product_id = (select product_id from Product where product_name ='Iphone'))
1084. 销售分析III
select p.product_id,p.product_name
from Product p left join Sales s on p.product_id=s.product_id
group by p.product_id
having min(s.sale_date)>='2019-1-1' and max(s.sale_date) <='2019-3-31'