How to do a SELECT with SUM and DISTINCT?

0

I need to make a select in the bank using sum and distinct. I tried this:

SELECT DISTINCT 'conta_idconta', SUM(valor) AS ValorTotal FROM contaSaida WHERE conta_empresa_idempresa=1 AND conta_subcategoria_idsubcategoria=4 AND data BETWEEN 2017-03-06 AND 2018-03-06

but returns me NULL

Tablecontents:

    
asked by anonymous 06.03.2018 / 19:51

1 answer

1

Why not use GROUPBY this way:

SELECT 
    conta_idconta, SUM(valor) AS ValorTotal 
FROM 
    contaSaida 
WHERE 
    conta_empresa_idempresa=1 AND conta_subcategoria_idsubcategoria=4 AND data BETWEEN '2017-03-06' AND '2018-03-06'
GROUP BY
    conta_idconta
    
06.03.2018 / 19:56