I need a table to store all the working days. I dont like loop, so I tried sql. The following is the SQL I used.

insert into tb_working_days(data_date,day_type)
select DATE_ADD(data_date,INTERVAL (select count(1) from tb_working_days) day),"W"
from tb_working_days ;

At first, I insert one date into the table.

Then I run this sql once, I get two rows. Run once more, I get four rows, as so on.

after 10 runs, I get more than 1000 rows. the work is done.

The most interesting point is the sql after Interval, and it makes the magic. The db is smart enough to convert a set into a int. that is amazing.

相关文章:

  • 2021-07-10
  • 2022-12-23
  • 2022-02-16
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
猜你喜欢
  • 2021-06-10
  • 2022-02-07
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案