Is there a way to use ORDER BY clause in COUNT aggregate analytic function? If not, what is a suitable alternative?
问题 I have a table of orders that looks something like this: WITH my_table_of_orders AS ( SELECT 1 AS order_id, DATE(2019, 5, 12) AS date, 5 AS customer_id, TRUE AS is_from_particular_store UNION ALL SELECT 2 AS order_id, DATE(2019, 5, 11) AS date, 5 AS customer_id, TRUE AS is_from_particular_store UNION ALL SELECT 3 AS order_id, DATE(2019, 5, 11) AS date, 4 AS customer_id, FALSE AS is_from_particular_store ) My actual table contains ~59 million rows. What I would like to do is essentially return