生成,然后在SQL中对随机数进行排序

时间:2018-02-25 21:11:59

标签: mysql sql

所以我使用SQL构建数学问题数据库。

我的典型查询可能如下所示:

SELECT @num1 := FLOOR(Rand()*8 + 2),@num2 := FLOOR(Rand()*8 + 2);
    INSERT INTO `QuestionDB`(TopicID, TopicName, SubtopicID, SubtopicName, Question, Answer, Difficulty, Author, Projectable) VALUES (3,"Multiplying",1,"Multiplying single digit numbers",CONCAT(@num1, " × ", @num2 ,"= "),@num1*@num2,1,"Me","Yes");

我使用PHPMyAdmin执行此操作并构建我的数据库。

这很好用。但是,我想做的是这样,所以我可以订购数字,即:

SELECT @num1 := FLOOR(Rand()),@num2 := FLOOR(Rand()),@num3 := FLOOR(Rand()),@num4 := FLOOR(Rand());
    INSERT INTO `QuestionDB`(TopicID, TopicName, SubtopicID, SubtopicName, Question, Answer, Difficulty, Author, Projectable) VALUES (7,"Ordering",1,"Ordering whole numbers",CONCAT("<span class='smaller'>Order, from highest to lowest</span><br>", @num1, " , ", @num2, etc),ORDER_ASS(@num1,@num2,@num3,@num4),1,"Me","Yes");

但是,显然ORDER_ASS不是一个有效的SQL函数。是否有SQL函数可以执行此操作?

0 个答案:

没有答案