mysql的七個聚合函數(shù) mysql怎么從集合中查詢數(shù)據?
mysql怎么從集合中查詢數(shù)據?1、選中需要測試的數(shù)據庫,并查看測試數(shù)據庫表;由于表t_people_info中的id是主鍵,求id的個數(shù)即是求數(shù)據庫表的總記錄數(shù),代碼如下:select count(
mysql怎么從集合中查詢數(shù)據?
1、選中需要測試的數(shù)據庫,并查看測試數(shù)據庫表;由于表t_people_info中的id是主鍵,求id的個數(shù)即是求數(shù)據庫表的總記錄數(shù),代碼如下:select count(id) from t_people_info
2、查看數(shù)據庫表t_people_info中年齡中最小值,需要用到集合函數(shù)min(),代碼如下:select min(p_age) from t_people_info
3、查看數(shù)據庫表t_people_info中年齡中最大值,需要用到集合函數(shù)max(),代碼如下:select max(p_age) from t_people_info
4、查看數(shù)據庫表t_people_info中年齡中平均值,需要用到集合函數(shù)avg(),代碼如下:select avg(p_age) from t_people_info
5、若想統(tǒng)計t_people_info中的年齡的總和,用到集合函數(shù)sum(),代碼如下:select sum(p_age) from t_people_info
6、統(tǒng)計數(shù)據庫表中記錄個數(shù),除了使用count(主鍵)外,可以使用count(1)、count(*)和count(0),代碼如下:select count(1) from t_people_infoselect count(*) from t_people_infoselect count(0) from t_people_info