首页 > 数据库技术 > 详细

SQL------聚集函数

时间:2018-11-10 14:49:09      阅读:168      评论:0      收藏:0      [点我收藏+]

 首先你要知道 where->group by->having->order by/limit  ,这个就是写sql语句时的顺序

5种常用的聚集函数

  MAX    求最大

  MIN    求最小

  SUM        求和

  AVG   求平均

  COUNT     计算总行数

注意:聚集函数不支持父子关联。例如:

Drop TABLE if exists t1;

drop table if exists t2;

create table t2(a int, b int, c int);

insert into t2 values(1,2,3);

insert into t2 values(2,2,2);

insert into t2 values(2,2,2);

insert into t2 values(3,2,2);

commit;

select b, c case when c > (select avg(t.b) from t2 ) then 1 else 0 end as d from t2 t group by c, b order by 1;   --该语句正常执行结果是要报错的。报错是正常的,不报错则有问题。

drop table if exists t2;

 

SQL------聚集函数

原文:https://www.cnblogs.com/kennyael/p/9938784.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!