query all table
select * from [table]
query specified column
select [column1],[column2] from [table]
set alias
select [column1] AS [alias1],[column2] AS [alias2] from [table]
Remove the same
select distinct([column]) from [table]
Operator
equal:
unequal:
greater than:
less than:
greater than or equal:
less than or equal:
equal | = |
unequal | != |
greater than | > |
less than | < |
greater than or equal | >= |
less than or equal | <= |
function
IS NULL:比较为空
IS NOT NULL:比较不为空
in:比较是否在其中
like:模糊查询
BETWEEN…AND…:比较是否在两这直接
and:与
or:或
not:非
排序
升序
select * from 表名 order by 列名
降序
select * from 表名 order by 列名 desc
查询数量
select top 数量 * from 表名select top 比例 percent * from 表名
条件日期
月
where month(列名) >= '数字'
日
where day(列名) >= '数字'
子查询
select *from 表名 where 列名 运算符 (select 列名 from 表名 where 条件 )
模糊查询
字段 link 条件
%:代表0个或多个字符 _:代表只有一个字符 [ ]:代表了限定范围 [^]:代表匹配不在范围内
聚合查询
count 求数量
max 求最大值
min 求最小值
sum 求和
avg 求平均
分组查询
group by 条件
笛卡尔乘积
select * from 表1,表2
依次排列出现结果
内连接
select * from 表名1 inner join 表名2 on 表名1.列名= 表名2.列名
外连接
left join以左表为主
右连接
right join以右表为主
全连接
full join 两张表无论是否符合关系都要显示