码迷,mamicode.com
首页 > 数据库 > 详细

SQL------聚集函数

时间:2018-11-10 15:12:23      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:exist   sql语句   creat   sel   语句   select   cas   color   bsp   

 首先你要知道 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------聚集函数

标签:exist   sql语句   creat   sel   语句   select   cas   color   bsp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!