Error - Select with SUM

0

Expensive;

I have a table with a lot of information, including a field with ticket_value and one with maturity.

I tried the query below, but without success:

SELECT * FROM boleto WHERE extract(year_month from vencimento) = 201805, (SUM(-valor_boleto)+5000) AS valor_boleto FROM boleto";

The error generated is syntax from Sum.

If I just run the current month sorting, it works correctly:

SELECT * FROM boleto WHERE extract(year_month from vencimento) = 201805;

Where am I going wrong, or do you have a simpler way of doing this query?

    
asked by anonymous 01.06.2018 / 22:29

1 answer

1

My friend, if I understood correctly what you want, I think that by grouping for the period you can get the sum of the values of the tickets as you wish, follow the code:

SELECT (SUM(valor_boleto)+5000) as soma, extract(year_month from vencimento) as periodo FROM boleto 
GROUP BY extract(year_month from vencimento);

follow the example: SqlFiddle

    
01.06.2018 / 22:52