Mysql常用函数:
一、使用limit限定输出个数
select * from user limit 3;select * from user limit 2,3;
二、mysql常用函数:
1、连接函数-concat()
select concat(username,'-',class_id) from user;
2、随机数-rand()
select * from user order by rand() limit 1;
3、统计表总行数-count()
select count(id) from user;
select count(*) from user;//*代表一个表中的主键,是mysql优化后的语句,比第一条快
4、求和-sum()
select sum(id) from user;
5、求平均值
select avg(id) from user;
6、求最大值
select max(id) from user;
7、求最小值
select min(id) from user;
8、group by分组聚合的使用
select class_id,count(id) from user group by class_id;
select concat(class_id,'-','class') class,count(*) sum from user group by class_id;