我想在 order by 之后选择一个随机行。我的结果有时会返回具有相同值的 2 行。所以我想做的是我想在返回的相同行之间随机选择 1 行。在下面的示例中,我想在返回的 2 个相同行之间返回 1 行。谢谢。select nondox, account, id from rates2 where weight='32' and country_code='US' and service like '%INT%' order by nondox,account上面查询的结果是nondox account id 276.16 610661731 25805209276.16 610798714 2108989391.68 610662766 1281799
2 回答
![?](http://img1.sycdn.imooc.com/5f33c0c90001f9ad05720572-100-100.jpg)
白衣非少年
TA贡献1155条经验 获得超0个赞
能否提供更多细节?
这将消除类似的 nondox 值,它不是完全随机的,但它应该有效。 select account, id , nondox from rates2 where weight='32' and country_code='US' and service like '%INT%' group by nondox order by nondox,account
![?](http://img1.sycdn.imooc.com/533e4cde000148e602000200-100-100.jpg)
人到中年有点甜
TA贡献1895条经验 获得超7个赞
您可以使用函数 RAND() 为表中的每一行生成一个随机值
SELECT * FROM table_name
ORDER BY RAND()
LIMIT 1;
- 2 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消