Add all records prior to a specific date - SQLite

1

I want to add multiple row values from my table (add up expense values) earlier than a specific date (for example, add all values that are smaller than the 2015-26-06 date). I am using the following code, but it is not functional.

SELECT SUM (VALOR) FROM despesa 
  WHERE strftime('%Y-m%-d%', data) <= strftime('%Y-m%-d%', '2015-06-30')
  AND pago = 1 AND idusuario = 1

Could anyone guide me in this? Thank you in advance.

Expense table structure

    
asked by anonymous 26.06.2015 / 16:38

2 answers

1

Do so

SELECT SUM (VALOR) FROM despesa WHERE data <= Datetime('2015-06-30 00:00:00') 
  AND pago = 1 AND idusuario = 1
    
26.06.2015 / 16:51
1

The error is here: strftime('%Y-m%-d%', data)

The function strftime(format, timestring, modifier, modifier, ...) only accepts string as the second argument and you are passing DATETIME .

Correct is as follows: data <= strftime('%Y-m%-d%', '2015-06-30') as per documentation .

Another cause that can return null is when the query does not return records.

    
26.06.2015 / 17:05