您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在 MySQL 中,我们如何随机化结果集中的行集或值集?

2024/5/17 9:05:13发布30次查看
借助与 order by 子句一起使用的 rand() 函数,可以在结果集中随机化行集或值集。要理解它,请考虑一个具有以下记录的表“employee” -
mysql> select * from employee;+----+--------+--------+| id | name | salary |+----+--------+--------+| 1 | gaurav | 50000 || 2 | rahul | 20000 || 3 | advik | 25000 || 4 | aarav | 65000 || 5 | ram | 20000 || 6 | mohan | 30000 || 7 | aryan | null || 8 | vinay | null |+----+--------+--------+8 rows in set (0.00 sec)
现在,下面的查询将使用 order bt rand() 来打乱结果集中的行集 -
mysql> select * from employee order by rand();+----+--------+--------+| id | name | salary |+----+--------+--------+| 4 | aarav | 65000 || 1 | gaurav | 50000 || 3 | advik | 25000 || 7 | aryan | null || 6 | mohan | 30000 || 8 | vinay | null || 5 | ram | 20000 || 2 | rahul | 20000 |+----+--------+--------+8 rows in set (0.00 sec)
以上就是在 mysql 中,我们如何随机化结果集中的行集或值集?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product