1158.sql (241B)
1 SELECT U.user_id AS buyer_id, 2 U.join_date, 3 COUNT(O.buyer_id) AS orders_in_2019 4 FROM Users U 5 LEFT JOIN ( 6 SELECT buyer_id 7 FROM Orders 8 WHERE YEAR(order_date) = 2019 9 ) AS O 10 ON U.user_id = O.buyer_id 11 GROUP BY U.user_id 12