LeetCode_Study_Plan/SQL

1158. Market Analysis I mysql

개발하는루루 2022. 10. 3. 19:12

https://leetcode.com/problems/market-analysis-i/

 

Market Analysis I - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

select u.user_id as buyer_id, u.join_date, IFNULL(tb.number, 0) as orders_in_2019
from (select buyer_id, count(order_id) as number from orders where order_date between "2019-01-01" and "2019-12-31" group by buyer_id) tb right join users u
on tb.buyer_id = u.user_id;