slq常用聚合函数
在数据库管理的集合函数或聚合函数是一个函数,其中多个行的值被组合在一起以形成单个摘要值。 <维基百科>
今天复习了下sql的聚合函数,做个笔记
先记几个要点:
- 聚合函数之后 不能再关联其他的值。
- 聚合函数只能得到一个值,要想获得多个值,需要配合使用group by :他的作用类似于去重,groupby可以限定 查找次数
- 聚合函数必须使用别名!基本上,创建别名是为了让列名称的可读性更强。
-count():计算数目,统计次数
select count( * ) from table where y = 1942 and d =1 ;
-max( * ):最大值 min( * ) :最小值
max ( age ) from table where grade = 1012
- sum():和值 svg():均值
一:
between 两者之间`
select * from table where y =>1980 and y<= 1990
select * from table where Y between 1980 and 1990
// between:介于两者之间 不过要在between之间加上字段名称(列名)
// ziduan between a and b
二:
模糊查询:like
select * from table where tit like ' 中国 %' ;//查找以中国开头的任意内容
// %a% %a a%
// where ziduan like '%a%';
三:
枚举 in
where y in (1970,1980,1990) ; //找出1970,1980,1990年的内容
where ziduan in (v1,v2,v3...)
四:
反向 not
where not 反向语句,可以嵌套上述所有语句,代表反义