mysql的七個(gè)聚合函數(shù) mysql怎么從集合中查詢數(shù)據(jù)?
mysql怎么從集合中查詢數(shù)據(jù)?1、選中需要測(cè)試的數(shù)據(jù)庫(kù),并查看測(cè)試數(shù)據(jù)庫(kù)表;由于表t_people_info中的id是主鍵,求id的個(gè)數(shù)即是求數(shù)據(jù)庫(kù)表的總記錄數(shù),代碼如下:select count(
mysql怎么從集合中查詢數(shù)據(jù)?
1、選中需要測(cè)試的數(shù)據(jù)庫(kù),并查看測(cè)試數(shù)據(jù)庫(kù)表;由于表t_people_info中的id是主鍵,求id的個(gè)數(shù)即是求數(shù)據(jù)庫(kù)表的總記錄數(shù),代碼如下:select count(id) from t_people_info
2、查看數(shù)據(jù)庫(kù)表t_people_info中年齡中最小值,需要用到集合函數(shù)min(),代碼如下:select min(p_age) from t_people_info
3、查看數(shù)據(jù)庫(kù)表t_people_info中年齡中最大值,需要用到集合函數(shù)max(),代碼如下:select max(p_age) from t_people_info
4、查看數(shù)據(jù)庫(kù)表t_people_info中年齡中平均值,需要用到集合函數(shù)avg(),代碼如下:select avg(p_age) from t_people_info
5、若想統(tǒng)計(jì)t_people_info中的年齡的總和,用到集合函數(shù)sum(),代碼如下:select sum(p_age) from t_people_info
6、統(tǒng)計(jì)數(shù)據(jù)庫(kù)表中記錄個(gè)數(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