mysql的七个聚合函数 mysql怎么从集合中查询数据?
mysql怎么从集合中查询数据?1、选中需要测试的数据库,并查看测试数据库表;由于表t_people_info中的id是主键,求id的个数即是求数据库表的总记录数,代码如下:select count(
mysql怎么从集合中查询数据?
1、选中需要测试的数据库,并查看测试数据库表;由于表t_people_info中的id是主键,求id的个数即是求数据库表的总记录数,代码如下:select count(id) from t_people_info
2、查看数据库表t_people_info中年龄中最小值,需要用到集合函数min(),代码如下:select min(p_age) from t_people_info
3、查看数据库表t_people_info中年龄中最大值,需要用到集合函数max(),代码如下:select max(p_age) from t_people_info
4、查看数据库表t_people_info中年龄中平均值,需要用到集合函数avg(),代码如下:select avg(p_age) from t_people_info
5、若想统计t_people_info中的年龄的总和,用到集合函数sum(),代码如下:select sum(p_age) from t_people_info
6、统计数据库表中记录个数,除了使用count(主键)外,可以使用count(1)、count(*)和count(0),代码如下:select count(1) from t_people_infoselect count(*) from t_people_infoselect count(0) from t_people_info