Reputation: 23
I'm trying to figure something out in mysql with an insert query but I'm in no good luck, so maybe you guys can help me out?
I have a database table with 3 values: ID(ai), Date en Status. I want to add date with the status 'test' on every Monday and Tuesday from today till end of the year. I want to create it in one time so no auto creation every month or something like that.
So normally I would create an insert query for every Monday and Tuesday that would mean a lot of work because I have to change the date in the query matching the Mondays and Tuesdays till the end of the year.
I there an insert query that can create on every Monday en Tuesday till the end of the year a new row with the data of that Monday or Tuesday and the value 'test' in the column status.
Normally I would use this:
INSERT INTO table1 (date, status) VALUES ('2020-08-17', 'test');
INSERT INTO table1 (date, status) VALUES ('2020-08-18', 'test');
INSERT INTO table1 (date, status) VALUES ('2020-08-24', 'test');
INSERT INTO table1 (date, status) VALUES ('2020-08-25', 'test');
As you can see that would mean a lot of copy/paste work but maybe there is a quick insert query that can do the trick :).
Thanks!!
Upvotes: 1
Views: 553
Reputation: 472
Starting from this:
INSERT INTO table1 (date, status) VALUES ('2020-08-17', 'test');
Then:
INSERT INTO table1 (date, status) SELECT MAX(date)+1, 'test' FROM table1;
INSERT INTO table1 (date, status) SELECT MAX(date)+6, 'test' FROM table1;
Repeat from Then
Upvotes: 1