The Question
SQLTop-Grossing Products per Category
Given a transactional dataset 'product_spend', write a query to identify the top two products by total revenue within each category for the fiscal year 2022. The solution must aggregate multiple transactions for the same product and handle categories with fewer than two products gracefully. Ensure the syntax is optimized for a columnar analytical database like ClickHouse.
Clickhouse
Window Func
CTE
RANK()
toYear()
Decimal
Aggregation