长话短说,我想创建一个列,重复1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,...etc模式。对于(12 * 460343 =) 5524116行。对我如何完成这件事有什么智慧吗?谢谢!
发布于 2015-07-02 17:48:18
插入说48,然后从自己中选择几次。你会很快到达那里的。它比人们想象的要快得多。
如果创建带有int autoinc列的表,则结束时:
delete from table where id>5524116
编辑在这里,你去
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 !
发布于 2015-07-02 18:19:17
使用一个循环,并对您的计数器做一些模块除法。
DECLARE @LoopCounter bigint
SET @LoopCounter = 0
CREATE TABLE #YourValues
(
YourValue_Key int NOT NULL identity (1,1) PRIMARY KEY,
YourValue_OneThrough12Repating int
)
WHILE @LoopCounter < 5524116
BEGIN
INSERT INTO #YourValues (YourValue_OneThrough12Repating) VALUES ((@LoopCounter % 12) + 1)
SET @LoopCounter = @LoopCounter + 1
END
SELECT * FROM #YourValues
DROP TABLE #YourValues
https://stackoverflow.com/questions/31191189
复制相似问题