Answer the question
In order to leave comments, you need to log in
SQL query to insert random data from other tables?
Good afternoon.
There is a table of questions Questions(id,Vopros,DisciplinaId....), a table of exams Exams(id,...,DisciplinaId,CountQuestions), users Users (id,....,GroupId) indicating the group to which the student
and progress Uspevaemost (UserId, EkzamenId, VoprosId, [Otvet] )
The algorithm is
1) adding data to the Exams table of 100 questions (CountQuestions) in the discipline (DisciplinaId) for the group (GroupId).
2)Get student id from GroupId
3)Get question id from DisciplinaId
4)Generate data and put it in table Uspevaemost
order by rand() with limit 100 (CountQuestions)
those. you do not need to write down all the questions, but only 100 random ones for each student who belongs to this group and for the discipline that is indicated.
In general, I rewarded and can not cope.
Confused how to write a request for generation. Tell me please.
Thanks
Answer the question
In order to leave comments, you need to log in
Such logic is easier to describe in the application. Get an array of question id's, shuffle, take the first 100. You can do ORDER BY RAND() LIMIT 100, but this is an extremely slow query.
$id_ekzamena=$_GET["id_ekzamena"]; //EXAM
$count_voprosov=$_GET["limit"]; //Number of questions
$id_group=$_GET["id_group"]; //Which group of students we add tests to - will return IDs of students in the group
$viborka_studentov =$this->Vipolnit_Zapros("SELECT idstudents as id FROM Studentsingroups WHERE idgroups=".$id_group);
//$count =count($viborka_studentov);
foreach ($viborka_studentov as $element) {
$this->Vipolnit_Zapros("INSERT INTO uspevaemostekzameni (IdVoprosa,IdEkzamena,IdUser)
SELECT vopros.id as IdVoprosa,'".$id_ekzamena."' AS IdEkzamena,".$element[' id']." AS IdUser FROM vopros ORDER BY RAND() LIMIT ". $count_voprosov);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question