1.生成随机数
select rand();
返回[0,1)之间的小数
如果想生成某个[min,max]之间的随机数 select min + rand()*(max - min),随机整数 select min + trunc(rand()*(max-min));
2. 分组聚合函数group_concat 相当于 oracle 的wm_concat
完整语法:
group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
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)