学习时间:
2023年2月17日
题目描述:
题解分享:
# 作 者 : 繁 华 倾 夏
# 力扣(LeetCode):1158. 市场分析 I
# MySQL 数据库
select Users.user_id as buyer_id, join_date, ifnull(UserBuy.cnt, 0) as orders_in_2019
from Users
left join (
select buyer_id, count(order_id) cnt
from Orders
where order_date between '2019-01-01' and '2019-12-31'
group by buyer_id
) UserBuy
on Users.user_id = UserBuy.buyer_id