luator
luator

Reputation: 5017

Add value from row to date in SELECT query

Assume I have the following SQLite table "foobar":

id | start      | duration
---+------------+---------
1  | 2016-05-12 | 2
2  | 2016-01-01 | 5

My goal is to get the sum of the start-date and the duration (durations are in years). So my desired result is the following:

id | end
---+-----------
1  | 2018-05-12
2  | 2021-01-01

Is this possible with a single query?

I know it is possible to add static values as follows

SELECT date(start, "+2 years") FROM foobar;

but I could not find a way to replace the static 2 with the dynamic value of duration.

Upvotes: 1

Views: 31

Answers (1)

juergen d
juergen d

Reputation: 204766

SELECT date(start, "+" || duration || " years") 
FROM foobar;

SQLFiddle demo

Upvotes: 2

Related Questions