Reputation: 1
My SQLite table structure is as follows:
Table: Income.
Columns: IncomeID, IncomeAmount, IncomeMonth, IncomeYear
How can i write a SQLite query to retrieve income Amounts between a given date range.
I know, we need to use date function, but i dont know how to specify two columns in it, i mean IncomeMonth and IncomeYear
Upvotes: 0
Views: 823
Reputation: 180080
If you know the year and month of the given date range, you do not need date functions.
A record is in the range if its year is after the range's start year, or, if both are in the same year, if the record's month is the same or after the range's start month. The comparions for the range end are similar:
SELECT *
FROM Income
WHERE ( IncomeYear > StartYear OR
(IncomeYear = StartYear AND IncomeMonth >= StartMonth))
AND ( IncomeYear < EndYear OR
(IncomeYear = EndYear AND IncomeMonth <= EndMonth))
Upvotes: 4