SQL查询一般包括: 简单查询,连接查询,聚合查询,嵌套子查询。
简单查询
select * from tableName //查询所有的列
select DISTINCT columnName from tableName //查询指定的列并消除重复的元组
select columnName 别名 from tableName //给查询的列取别名
select columnName AS 别名 from tableName
下面是where 子句中常用的查询条件:
1.比较运算:>,<,=,>=,<=,<>(!=);
select * from tableName where num >=20
2.范围查询:BETWEEN … AND …
select * from tableName where score BETWEEN 60 AND 90
3.集合查询:IN
select * from tableName where classNo IN ('001','002')
select * from tableName where classNo NOT IN ('001','002')
4.空值查询:IS null
select * from tableName where class IS null
5.字符匹配查询:LIKE;
select * from tableName where name LIKE '%小%'
select * from tableName where name LIKE '陈_ _'
select * from tableName where className LIKE '%08/_%' ESCAPE '/'
6.逻辑查询:AND,OR,NOT。
select * from tableName where class IS null AND name LIKE '%小%'