加入收藏 | 设为首页 | 会员中心 | 我要投稿 拼字网 - 核心网 (https://www.hexinwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

使用SQL聚合函数与排序的注意事项有哪些

发布时间:2022-02-18 08:44:11 所属栏目:MySql教程 来源:互联网
导读:这篇文章主要介绍了使用SQL聚合函数与排序的注意事项有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。 count 函数 语法: Select count(*)|count(列名) from table_name [where wh
      这篇文章主要介绍了使用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;
 
       感谢你能够认真阅读完这篇文章,希望小编分享的“使用SQL聚合函数与排序的注意事项有哪些”这篇文章对大家有帮助。

(编辑:拼字网 - 核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!