SQL5---条件查询
程序员文章站
2023-03-08 14:02:38
1:条件查询(1)语法:select 查询列表(3) from 表名 (1) where 筛选条件; (2)(2):分类按条件表达式筛选条件运算符:> < =...
1:条件查询
(1)语法:
select
查询列表(3)
from
表名 (1)
where
筛选条件; (2)
(2)分类
A:按条件表达式筛选
条件运算符:> < = != <> >= <=
例子1:查询工资大于12000的员工信息
SELECT
*
FROM
employees
WHERE
salary>12000;
例子2:查询部门编号不等于90号的员工名和部门编号
法一:
SELECT
last_name.
department_id;
FROM
employee
WHERE
department_id!=90;
法二:
SELECT
last_name.
department_id;
FROM
employee
WHERE
department_id<>90;
B:按逻辑值表达式筛选
逻辑运算符 && || !
and or not
例子1:查询工资在10000或者20000之间的员工名、工资以及奖金
SELECT
last_name,
salary,
comission_pct
From
employees
WHERE
salary>=10000 AND salary<=20000;
法二:查询部门编号不是在90~100之间,或者工资高于15000的员工信息
SELECT
*
FROM
employees
Where
NOT(department_ID>=90 AND department_id<=110) OR salary>15000;
2:模糊查询
like
between…and…
in
is null
(1)like
A:一般和通配符搭配使用
通配符:% 任意多个字符,包含0字符
_任意单个字符
例1:查询员工名中包含字符a的员工信息
SELECT
*
FROM
employees
WHERE
last_name Like '%A%';#abc
例2:查询员工名字中第三个字符是n,第五个字符是l 的员工名和工资
SELECT
last_name,
salary
FROM
employees
WHERE
last_name Like '_n_l%';
例3:查询员工名中第二个字符为_的员工名
法一:
SELECT
last_name
FROM
employees
WHERE
last_name LIKE '_\_%';
法二:
SELECT
last_name
FROM
employees
WHERE
last_name LIKE '_$_%' ESCAPE '$';
本文地址:https://blog.csdn.net/zsysingapore/article/details/107307845
上一篇: 荐 MYSQL——数据处理之增删改
下一篇: 常用排序算法c#