I'm trying to copy the contents of certain columns in one table to another table, while adding 2 extra columns containing random numbers, and at the same time concatenate those same values with the parameterValues. My problem: If I do the following it only generates the random numbers once, and all my rows end up with the same extra 2 values.
SET @InitialConditions_y0= FLOOR(-10 + (rand() * 20));
SET @InitialConditions_y1= FLOOR(-10 + (rand() * 20));
INSERT INTO testing (parameters, type, InitialConditions_y0, InitialConditions_y1)
SELECT CONCAT(parameterValues, " ; ",@InitialConditions_y0, "," ,@InitialConditions_y1), '10',
@InitialConditions_y0, @InitialConditions_y1
FROM QuestionInstances WHERE ProblemType = 3;
But if I do this
INSERT INTO testing (parameters, type, InitialConditions_y0, InitialConditions_y1)
SELECT CONCAT(parameterValues, " ; ", FLOOR(-10 + (rand() * 20)), "," , FLOOR(-10 + (rand() * 20))), '10',
FLOOR(-10 + (rand() * 20)), FLOOR(-10 + (rand() * 20))
FROM QuestionInstances WHERE ProblemType = 3;
Then I don't get the same numbers saved to the columns as the ones concatenated, as each is an individually generated random number.
I thought about not copying that column at first and updating it later, but it cannot be left empty, and it has a UNIQUE key constraint.
Aucun commentaire:
Enregistrer un commentaire