इस तरह से प्रयास करें:
INSERT INTO table1( userID,credID,time)
SELECT x,y,'2013-12-12'
FROM (
SELECT 1 As x union
SELECT 2 union
SELECT 3 union
SELECT 4 union
SELECT 5
) xx
CROSS JOIN (
SELECT 10 As y union
SELECT 11 union
SELECT 12 union
SELECT 13 union
SELECT 15 union
SELECT 16 union
SELECT 17 union
SELECT 18 union
SELECT 19 union
SELECT 20
) yy
डेमो:http://www.sqlfiddle.com/#!2/8398d/1
संपादित करें।
यदि संख्याओं की ये दो सूचियाँ सघन हैं, तो संख्याओं की तालिका के साथ एक और तरकीब है:
CREATE TABLE numbers( x int primary key auto_increment );
INSERT INTO numbers
SELECT null FROM information_schema.columns
LIMIT 100;
CREATE TABLE table2
(userID int,credID int,time date);
INSERT INTO table2( userID,credID,time)
SELECT n1.x,n2.x,'2013-12-12'
FROM numbers n1
CROSS JOIN numbers n2
WHERE n1.x BETWEEN 1 AND 5
AND n2.x BETWEEN 10 AND 20
;
डेमो:http://www.sqlfiddle.com/#!9/e121d/1
संपादित करें।
CREATE TABLE numbers( x int primary key auto_increment );
INSERT INTO numbers
SELECT null FROM information_schema.columns
LIMIT 100;
CREATE TABLE table1
(userID int,credID int,time date);
INSERT INTO table1( userID,credID,time)
SELECT xx,yy,'2013-12-12'
FROM (
SELECT reverse( if( locate(',',reverse(SUBSTRING_INDEX( y, ',', x ))) > 0,
substr( reverse(SUBSTRING_INDEX( y, ',', x )), 1, locate(',',reverse(SUBSTRING_INDEX( y, ',', x ))) -1 ),
reverse(SUBSTRING_INDEX( y, ',', x ))
)) AS xx
FROM ( select '1,22,333,44,51,656' y ) q
JOIN numbers n
ON n.x <= length( y ) - length( replace( y, ',','')) + 1
) q1
CROSS JOIN
(
SELECT reverse( if( locate(',',reverse(SUBSTRING_INDEX( y, ',', x ))) > 0,
substr( reverse(SUBSTRING_INDEX( y, ',', x )), 1, locate(',',reverse(SUBSTRING_INDEX( y, ',', x ))) -1 ),
reverse(SUBSTRING_INDEX( y, ',', x ))
)) AS yy
FROM ( select '111,222,3333,444,54,656' y ) q
JOIN numbers n
ON n.x <= length( y ) - length( replace( y, ',','')) + 1
) q2
;
डेमो --> http://www.sqlfiddle.com/#!9/83c86 /1