数据库总结.5

来源:互联网 发布:德语识别算法 编辑:程序博客网 时间:2024/06/03 16:49

投影操作:select 列名列表 from表名

关键字;select、from、where、order by、distinct、group by

表名前缀:select 表名.列名 from 表名

列别名:select 列a AS列b from表名

计算列:select 列名+-*/ from 表名

连接列名:‘’,concat,‘’

排除重复:select distinct 列名 from 表名

返回限定查询行数:select TOP 列名,from 表名

选择操作:select 列名 from表名 where 过滤条件

多条件选择:OR:至少满足两个中的一个条件 AND:同事满足两个条件 not

使用:select 列a from 表 where a=1 and b=0     select 列a from 表 where a=1 or b=0

执行范围测试:between     select 列a from 表名 where 列a between xxx and xxx(包含上限下限)

可以加not排除  select 列a from 表名 where 列a not  between xxx and xxx

定义集合关系:select 列a from 表名 where 列c=xxx or c=zzz        select 列a from 表名 where  列c in(xxx  zzz)

可加not排除 select 列a from 表名 where  列c not  in(xxx  zzz)

模糊查询:select 列a,列b from 表 where 列c like 模式

模式:'%xxx%'包含xxx           '%xxx'y以xxx结尾           'xxx%'以xxx开始     ‘--’以两个字(-表示一个字符)

处理空数据:is null  为空     is not null 不为空

排序操作:select 列a, 列b from 表 order 列a  ASC

asc:升序    desc:降序

聚合函数:count、sum、avg、max、min

执行行和列计数:select count(计数规范) from 表名

计数规范:*:所有行,包括null值   all:所有非空行   distinct:排除重复统计的行

返回列和值:select sum(列名) from 表

获取平均值:select avg (列名) from 表

返回最大(小)值:select max(最大值规范) from 表名       select min(最小值规范) from 表名

过滤分组:select 列,聚合函数 from 表名 where 过滤 group by 列

having:select 列,聚合函数 from 表名 where 过滤 group by 列 having 聚合函数()>xxx  or  聚合函数()<xxx


0 0