Closed shubhamphegade closed 1 year ago
Great sharing, thanks.
Since both 'sushi' and 'curry' are puchased on the same day (2021-01-01), they should both be included
The order_date
field does not have a timestamp, hence it is impossible to determine the exact sequence of items ordered by the customer.
Therefore, it would be inaccurate to conclude that curry is the customer's first order purely based on the alphabetical order of the product names.
For this reason, I maintain my solution of using DENSE_RANK()
and consider both curry and sushi as Customer A's first order.
@katiehuangx --3. What was the first item from the menu purchased by each customer? WITH ordered_sales_cte AS
(
)
SELECT customer_id, product_name FROM ordered_sales_cte WHERE rank = 1 GROUP BY customer_id, product_name;
--Using dense_rank:
--Using row_number(correct one):