数据库
首页 > 数据库> > <数据库> Leetcode1511. 消费者下单频率

<数据库> Leetcode1511. 消费者下单频率

作者:互联网

 

写一个 SQL 查询,报告在 2020 年 6 月和 7 月 每个月至少花费 $100 的客户的 customer_id 和 customer_name 。

以任意顺序返回结果表.

查询结果格式如下例所示。

 

# 2020 年 6 月和 7 月 
# 每个月至少花费 $100 的客户的 customer_id 和 customer_name 
select c.customer_id,c.name
from customers c
join orders o on o.customer_id=c.customer_id
join product p on p.product_id=o.product_id
where year(order_date)=2020
group by c.customer_id
having sum(case when month(order_date)=6 then p.price*o.quantity else 0 end) >=100
and sum(case when month(order_date)=7 then p.price*o.quantity else 0 end) >=100

 

标签:customer,product,name,数据库,下单,date,Leetcode1511,100,id
来源: https://blog.csdn.net/qq_36895331/article/details/123192757