SQL的聚合函数与排序


本文摘自PHP中文网,作者php中世界最好的语言,侵删。

这次给大家带来SQL的聚合函数与排序,使用SQL聚合函数与排序的注意事项有哪些,下面就是实战案例,一起来看一下。

count 函数

语法:

1

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函数

1

2

3

4

5

6

7

8

9

10

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 子句排序查询结果

1

Select column1, column2, column3 from table order by column asc|desc

order by指排序的列,也可以是select后面指定的列名

order by 子句应位于select 语句的结尾

1

2

3

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;

2091014-cddde956b411ea7e.png

2091014-9c52af8396187699.png

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

分页查询的使用详解

JS的日期相关函数使用详解

以上就是SQL的聚合函数与排序的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

详解oracle中的translate函数和replace函数

详解oracle中存储函数与存储过程

sql的聚合函数与排序

解析mysql存储过程、常用函数代码

mysql中常用的的内置函数

总结sql server中常用函数使用方法

mysql 常用的三类函数

详解mysql中order by多字段排序规则

详解oracle常用函数trunc

mysql常用函数大全

更多相关阅读请进入《排序》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...