SQL------彙集函數

 首先你要知道 where->group by->having->order by/limit  ,這個就是寫sql語句時的順序sql

5種經常使用的彙集函數函數

  MAX    求最大spa

  MIN    求最小it

  SUM        求和table

  AVG   求平均select

  COUNT     計算總行數sql語句

注意:彙集函數不支持父子關聯。例如:im

Drop TABLE if exists t1;tab

drop table if exists t2;vi

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;

相關文章
相關標籤/搜索