select rand();
返回[0,1)之间的小数
如果想生成某个[min,max]之间的随机数 select min + rand()*(max - min),随机整数 select min + trunc(rand()*(max-min));
create table a(id int primary key auto_increment,staffid varchar(20),roleid varchar(20));
insert into a(staffid,roleid) values('a','admin');
insert into a(staffid,roleid) values('a','safeadmin');
insert into a(staffid,roleid) values('b','general');
insert into a(staffid,roleid) values('b','planer');
mysql> select staffid,group_concat(roleid order by roleid) from a group by staffid;
+---------+--------------------------------------+
| staffid | group_concat(roleid order by roleid) |
+---------+--------------------------------------+
| a | admin,safeadmin |
| b | general,planer |
+---------+--------------------------------------+
2 rows in set (0.00 sec)