简单查询
SELECT 字段 FROM 表名;
SELECT * FROM table;
SELECT name,salary FROM table;
SELECT ename AS '姓名',salary as '工资' FROM emp;
去重操作
SELECT DISTINCT 字段 FROM 表名;
SELECT DISTINCT name FROM table;
运算查询
SELECT
ename AS '姓名',
salary + 1000 AS '工资'
FROM
emp;
条件查询
SELECT 列名 FROM 表名 WHERE 条件表达式;
运算符 | 说明 |
---|---|
> < <= >= = <> != | <> != 都是不等于 |
BETWEEN ...AND... | 显示在某一区间的值 例如: 2000-10000之间: Between 2000 and 10000 |
IN(集合) | 集合表示多个值,使用逗号分隔,例如: name in (悟空,八戒) |
LIKE '%王%' | 模糊查询 |
IS NULL | 查询某一列为NULL的值, 注: 不能写 = NULL |
where name!='张三'
where name<>'李四'
where age>18
where age>=18
where age<30
where age<=30
where age between 18 and 30;
where name in ('张三','李四')
where name like '%王%' -- name中有王这个字
where name like '王%' -- name中以王开头
where name like '%王' -- name中以王结尾
where name like '_三%' -- 第二个字为三的
name IS NOT NULL -- 名字不为空
运算符 | 说明 |
---|---|
And && | 条件同时成立 |
Or | 条件任一成立 |
Not | 条件不成立 |
表别名
SELECT * FROM table t WHERE t.name = 5000;
网友评论