Perform query MAX () within a SUM () in SQL

-1

I have a query which shows me the sum of money by means of a SUM() and shows the VALOR of the money grouped by PLACA in this way:

SELECT PLACA, SUM(VALOR) AS SUMA 
FROM 'huawei_combustible' 
WHERE YEAR(FECHA_TANQUEO) = 2018 AND MONTH(FECHA_TANQUEO) = 01 
GROUP BY PLACA  
ORDER BY 'SUMA' DESC

But what I need is to be able to show the maximum value of that first query. something like this:

SELECT PLACA, SUM(VALOR) AS SUMA
(SELECT MAX(SUMA) FROM 'huawei_combustible') 
FROM 'huawei_combustible'
WHERE YEAR(FECHA_TANQUEO) = 2018 AND MONTH(FECHA_TANQUEO) = 01
    
asked by Anderviver 25.01.2018 в 23:22
source

1 answer

1

The answer I can give you I know that it would work with a Postgres or MySql Database. I hope you find it useful:

Solution:

SELECT PLACA, SUM(VALOR) AS SUMA 
FROM 'huawei_combustible' 
WHERE YEAR(FECHA_TANQUEO) = 2018 AND MONTH(FECHA_TANQUEO) = 01 
GROUP BY PLACA  
ORDER BY 'SUMA' DESC
LIMIT 1
    
answered by 25.01.2018 / 23:40
source