Reputation: 19
so i have tables with 2 fields
date | date_add |
---|---|
2022-08-01 | 5 |
2022-08-01 | 3 |
and i want this output for my query
date | date_add | due_date |
---|---|---|
2022-08-01 | 5 | 2022-08-06 |
2022-08-01 | 3 | 2022-08-04 |
Upvotes: 0
Views: 42
Reputation: 780974
Use the DATE_ADD()
function.
SELECT date, date_add, DATE_ADD(date, INTERVAL date_add DAY) AS due_date
FROM yourTable
You could also define a virtual column to do this automatically.
ALTER TABLE yourTable
ADD COLUMN due_date GENERATED ALWAYS AS DATE_ADD(date, INTERVAL date_add DAY) VIRTUAL;
Upvotes: 1