这次给大家带来SQL的聚合函数与排序,使用SQL聚合函数与排序的注意事项有哪些,下面就是实战案例,一起来看一下。
count 函数
语法:
Select count(*)|count(列名) from table_name [where where_defination];Select count(id) from stu;Select count(name) from stu where math > 90;select count (name) from stu where chines+math+English> 250;
sum函数
Select sum (列名) from stu [where where_defination]; Select sum (列名),sum(列名), sum(列名) from stu [where where_definition]; Select sum (列名)+sum(列名)+ sum(列名) from stu [where where_definition]; Select sum (列名)+sum(列名)+sum(列名) as 总分 from stu [where where_definition]; Select sum (列名)/count(name) from stu [where where_defination]; Select avg(math) from stu; Select avg(math + chines + english) from stu; Select max|min(列名) from stu; Select max(math + chines + english) from stu; Select min(math + chines + english) from stu;
对查询结果排序
使用order by 子句排序查询结果
Select column1, column2, column3 from table order by column asc|desc
order by指排序的列,也可以是select后面指定的列名
order by 子句应位于select 语句的结尾
Select name, math from stu order by math; select name, math+english+chines from stu order by math+english+chines desc; select name, math+english+chines from stu where name like 'zhang%' order by math+english+chines desc;


相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
MallWWI新模式返利商城系统基于成熟的飞蛙商城系统程序框架,支持多数据库配合,精美的界面模板,人性化的操作体验,完备的订单流程,丰富的促销形式,适合搭建稳定、高效的电子商务平台。创造性的完美整合B2B\B2C\B2S\C2B\C2C\P2C\O2O\M2C\B2F等模式,引领“互联网+”理念,实现商家联盟体系下的线上线下全新整合销售方式,独创最流行的分红权返利与排队返钱卡功能。安全、稳定、结构









