我需要一种聪明的方法来生成 6 个数字,在 1 到 49 之间没有重复,并将每个数字插入到列中。下面是我在 phpmyadmin 中创建的程序,它插入了重复的数字。
BEGIN
DECLARE liczba1 INT;
DECLARE liczba2 INT;
DECLARE liczba3 INT;
DECLARE liczba4 INT;
DECLARE liczba5 INT;
DECLARE liczba6 INT;
DECLARE check INT;
DECLARE count1 INT;
set count1 = 0;
while count1 < howMany DO
SELECT FLOOR(RAND()*(49-1)+1) into liczba1;
SELECT FLOOR(RAND()*(49-1)+1) into liczba2;
SELECT FLOOR(RAND()*(49-1)+1) into liczba3;
SELECT FLOOR(RAND()*(49-1)+1) into liczba4;
SELECT FLOOR(RAND()*(49-1)+1) into liczba5;
SELECT FLOOR(RAND()*(49-1)+1) into liczba6;
INSERT INTO kupony VALUES(NULL, 1, liczba1, liczba2, liczba3, liczba4, liczba5, liczba6, -1, '2018-01-01', -1);
set count1 = count1 + 1;
end while;
END