Add values to a mysql count

0

Good Night, I'm having a doubt I have a system that runs the following query:

SELECT IDUsuario ,COUNT('TotalDeUps') as Total,  FROM uploads
        WHERE Time >= '2018-02-20 00:00:00'
        AND Time < '2018-03-21 00:00:00'
GROUP BY IDUsuario
ORDER BY COUNT("UserID") DESC

I have this table uploads a column called Size, I would like to know if I can add the size values of an ID to return, I thought of something like that just did not work:

SELECT IDUsuario ,COUNT('TotalDeUps') as Total,SUM(Size) as TotalDeUp  FROM uploads
        WHERE Time >= '2018-02-20 00:00:00'
        AND Time < '2018-03-21 00:00:00'
GROUP BY IDUsuario
ORDER BY COUNT("UserID") DESC

The result was zero for all columns.

    
asked by anonymous 24.02.2018 / 02:49

1 answer

0

You probably have some rows with the NULL value in the size column. Use COALESCE to consider these values as 0 :

...
SUM(COALESCE(Size, 0)) AS TotalDeUp
...
    
24.02.2018 / 03:29