sahnaz3
sahnaz3

Reputation: 19

How can i add date based on my data at sql?

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

Answers (1)

Barmar
Barmar

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

Related Questions