您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

SQL的聚合函数与排序

2024/3/26 12:51:16发布15次查看
这次给大家带来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;
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
分页查询的使用详解
js的日期相关函数使用详解
以上就是sql的聚合函数与排序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product