Товары, с которых клиенты начинают
Questions like this come up in interviews at Самокат
Level: MiddleTopic: CTE100 XP
Instructions
Первый заказ клиента — его самый ранний по created_at заказ со статусом, отличным от 'cancelled' (при равенстве created_at — с меньшим id). Для каждого товара посчитайте first_cnt — в скольких первых заказах клиентов он есть. Выведите 3 товара с наибольшим first_cnt (при равенстве first_cnt выше стоит товар с меньшим product_id): product_id и first_cnt. Порядок строк не важен.
not translated yetHints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Exactly oneZero or oneZero or more
Table relationships
- N:1Many-to-one
order_items.→order_id orders.id - N:1Many-to-one
order_items.→product_id products.id - N:1Many-to-one
orders.→customer_id customers.id - N:1Many-to-one
products.→category_id categories.id
Table data
PostgreSQL
Select a table in the diagram or list to view its rows.