79313200

Date: 2024-12-28 04:11:37
Score: 1
Natty:
Report link

Try below query

WITH SalesData AS (
    SELECT
        product_type,
        geography,
        SUM(quantity_sold) AS total_sold
    FROM product_sales
    GROUP BY product_type, geography
),
RankedSales AS (
    SELECT
        product_type,
        geography,
        total_sold,
        ROW_NUMBER() OVER (PARTITION BY product_type ORDER BY total_sold DESC) AS rn
    FROM SalesData
)
SELECT
    product_type,
    geography,
    total_sold
FROM RankedSales
WHERE rn = 1
ORDER BY product_type;

db-fiddle

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Sharad Paul