为了账号安全,请及时绑定邮箱和手机立即绑定

MYSQL pickup Random row after order by

MYSQL pickup Random row after order by

PHP
慕容708150 2023-04-21 09:55:27
我想在 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 回答

?
白衣非少年

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

查看完整回答
反对 回复 2023-04-21
?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

您可以使用函数 RAND() 为表中的每一行生成一个随机值


SELECT * FROM table_name

ORDER BY RAND()

LIMIT 1;


查看完整回答
反对 回复 2023-04-21
  • 2 回答
  • 0 关注
  • 104 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信