Skip to content
Advertisement

How can I find the max “income” from every “product” in every “province”? [closed]

I have this table

PRODUCT PROVINCE INCOME
Apple Seville 13.2
Melon Almeria 3.6

I tried this:

SELECT
    PRODUCT,
    PROVINCE,
    MAX(TOTAL)
FROM
    (
        SELECT
            PRODUCT,
            PROVINCE,
            SUM(INCOME) TOTAL
        FROM  SALES
        GROUP BY  PRODUCT,PROVINCE
    )
GROUP BY PRODUCT,PROVINCE;

Advertisement

Answer

SELECT PRODUCTO, PROVINCIA
FROM VENTAS 
WHERE RECAUDACION IN (SELECT MAX(RECAUDACION)
FROM VENTAS
GROUP BY PROVINCIA)
GROUP BY PROVINCIA, PRODUCTO;
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement