聚合函数和排序

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;

结果示例:

屏幕快照 2017-11-07 上午11.07.46.png
屏幕快照 2017-11-07 上午11.07.25.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容