如何同时选择ORDER BY列和RAND()? [英] How to select ORDER BY column and RAND() both?
本文介绍了如何同时选择ORDER BY列和RAND()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,亲爱的朋友.
mysql_query("SELECT id FROM tb_table ORDER BY num ASC, ORDER BY RAND() LIMIT 1");
此编码正确吗? 我想查找ASC num的所有行,并且可以有1000 num为1的行,另外1000 num为2的行. 但是我希望它首先将ASC排序为1,然后随机选择其中之一.
is this coding correct? I want to find all rows ASC num and there can be 1000 rows that num is 1 another 1000 that num is 2. But I want it to sort ASC like 1s firstly and choose one of them randomly.
推荐答案
您只需指定一次ORDER BY
.
mysql_query("SELECT id FROM tb_table ORDER BY num ASC, RAND() LIMIT 1");
这篇关于如何同时选择ORDER BY列和RAND()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文