MYSQL如何随机读取多个分类中的某一条数据

NOCO发布于 来源 原文链接

1天前 有1个用户阅读过

mysql> Select id, name ,val,memo from (select * from tb order by rand())t group by name limit 0,30 ;
+—-+——+——+——+
| id | name | val | memo |
+—-+——+——+——+
| 1 | a | 2 | a2 |
| 6 | b | 2 | b2 |
| 7 | c | 1 | c1 |
+—-+——+——+——+
3 rows in set (0.00 sec)

mysql> Select id, name ,val,memo from (select * from tb order by rand())t group by name limit 0,30 ;
+—-+——+——+——+
| id | name | val | memo |
+—-+——+——+——+
| 2 | a | 1 | a1 |
| 4 | b | 1 | b1 |
| 7 | c | 1 | c1 |
+—-+——+——+——+
3 rows in set (0.01 sec)

mysql> Select id, name ,val,memo from (select * from tb order by rand())t group by name limit 0,30 ;

+—-+——+——+——+
| id | name | val | memo |
+—-+——+——+——+
| 3 | a | 3 | a3 |
| 6 | b | 2 | b2 |
| 7 | c | 1 | c1 |
+—-+——+——+——+

-- The End --

本文标题: MYSQL如何随机读取多个分类中的某一条数据

本文地址: https://seonoco.com/blog/mysql-how-to-read-one-of-the-multiple-data-in-a-random-way

原文地址: http://bbs.csdn.net/topics/390192118

本文是否有所帮助?
点赞 0
感谢支持
0
多谢反馈
评论 0
打赏

支持微信/支付宝

评论

网友