A SQL to insert continuous values

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.

posted @ 2013-07-09 22:22  永远是学生  阅读(204)  评论(0编辑  收藏  举报