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

44次阅读
没有评论

共计 1309 个字符,预计需要花费 4 分钟才能阅读完成。

自动写代码机器人,免费开通

这篇文章主要介绍了使用 SQL 聚合函数与排序的注意事项有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让丸趣 TV 小编带着大家一起了解一下。

使用 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 聚合函数与排序的注意事项有哪些

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

感谢你能够认真阅读完这篇文章,希望丸趣 TV 小编分享的“使用 SQL 聚合函数与排序的注意事项有哪些”这篇文章对大家有帮助,同时也希望大家多多支持丸趣 TV,关注丸趣 TV 行业资讯频道,更多相关知识等着你来学习!

向 AI 问一下细节

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-04发表,共计1309字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)