使用SQL聚合函数与排序的注意事项有哪些
这篇文章主要介绍了使用SQL聚合函数与排序的注意事项有哪些,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
使用SQL聚合函数与排序的注意事项有哪些
count 函数
语法:
Selectcount(*)|count(列名)fromtable_name[wherewhere_defination];Selectcount(id)fromstu;Selectcount(name)fromstuwheremath>90;selectcount(name)fromstuwherechines+math+English>250;
sum函数
Selectsum(列名)fromstu[wherewhere_defination];Selectsum(列名),sum(列名),sum(列名)fromstu[wherewhere_definition];Selectsum(列名)+sum(列名)+sum(列名)fromstu[wherewhere_definition];Selectsum(列名)+sum(列名)+sum(列名)as总分fromstu[wherewhere_definition];Selectsum(列名)/count(name)fromstu[wherewhere_defination];Selectavg(math)fromstu;Selectavg(math+chines+english)fromstu;Selectmax|min(列名)fromstu;Selectmax(math+chines+english)fromstu;Selectmin(math+chines+english)fromstu;
对查询结果排序
使用order by 子句排序查询结果
Selectcolumn1,column2,column3fromtableorderbycolumnasc|desc
order by指排序的列,也可以是select后面指定的列名
order by 子句应位于select 语句的结尾
Selectname,mathfromstuorderbymath;selectname,math+english+chinesfromstuorderbymath+english+chinesdesc;selectname,math+english+chinesfromstuwherenamelike'zhang%'orderbymath+english+chinesdesc;
感谢你能够认真阅读完这篇文章,希望小编分享的“使用SQL聚合函数与排序的注意事项有哪些”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。