数据库(2) SQL查询--简单查询

来源:互联网 发布:时代中安网络 编辑:程序博客网 时间:2024/06/07 17:00

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 '%小%'
1 0
原创粉丝点击