0
点赞
收藏
分享

微信扫一扫

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

AbrahamW 2022-03-10 阅读 99
数据库

 

写一个 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

 

举报

相关推荐

0 条评论