SQL Server:如何使用重复序列1-12创建列?

Wal*_*ker 6 sql sql-server-2012

长话短说,我想创建一个重复1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,...的模式的列.等等 for(12*460343 =)5524116行.关于如何完成这个的任何智慧?谢谢!

Dre*_*rew 4

插入说 48,然后从 self 中选择几次。你会很快到达那里。它比人们想象的要快得多。

如果您创建一个带有 int autoinc 列的表,那么最后:

delete from table where id>5524116
Run Code Online (Sandbox Code Playgroud)

在这里编辑即可

    create table idFix
    (   id bigint auto_increment primary key,
        num int not null
    )engine=myisam;

    -- prime it    
    insert into idFix(num) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);

    -- this is pretty fast, don't laugh
    -- run the following line 19 times
    insert into idFix(num) select num from idFix;

    -- you now have 6.2m rows (6,291,456)
    select count(*) from idFix

    delete from idFix where id>5524116;

    select count(*) from idFix;

    select min(num),max(num) from idFix;

Takes 3 minutes max

Use your helper table then for the love of Pete drop it !
Run Code Online (Sandbox Code Playgroud)