当前位置:网站首页>条件查询
条件查询
2022-06-26 04:28:00 【莉莉妖_】
语法:SELECT 查询列表 FROM 表名 WHERE 筛选条件;
- 按条件表达式筛选
简单条件运算符:<>=(!=<>)>=<= - 按逻辑表达式筛选
逻辑运算符:ANDORNOT - 模糊查询
LIKEBETWEEN ANDINIS NULL
按条件表达式筛选
#1. 查询工资 > 12000 的员工信息
SELECT * FROM employees WHERE salary > 12000;
#2. 查询部门编号不等于 90 的员工名和部门编号
SELECT
CONCAT(last_name, " ", first_name) AS 员工名,
department_id
FROM
employees
WHERE
department_id <> 90; # 不等于
按逻辑表达式筛选
AND
#1. 查询工资在 10000 到 20000 之间的员工名,工资和奖金
SELECT
CONCAT(last_name, " ", first_name) AS 员工名,
salary,
commission_pct
FROM
employees
WHERE
salary >= 10000
AND salary <= 20000;
OR / NOT
#2. 查询部门编号不是在 90 到 110 之间,或者工资高于 15000 的员工信息
SELECT
*
FROM
employees
WHERE
NOT (department_id >= 90 AND department_id <= 110)
OR salary > 15000;
模糊查询
LIKE
- 一般和通配符搭配使用
- 通配符:
%:任意多个字符,_:任意单个字符
#1. 查询员工名中包含字符“a”的员工信息
SELECT * FROM employees WHERE last_name LIKE "%a%";
#2. 查询员工名中第三个字符为"n",第五个字符为"l"的员工名和工资
SELECT last_name,salary
FROM employees where last_name LIKE "__n_l%";
#3. 查询员工名中第二个字符为“_”的员工名
# (使用转义字符 \ 或 任意字符 使用 ESCAPE)
SELECT last_name
FROM employees WHERE last_name LIKE "_$_%" ESCAPE "$";
BETWEEN AND
- 包含左右临界值
#1. 查询员工编号在 100 到 120 之间的员工信息
SELECT * FROM employees WHERE employee_id BETWEEN 100 AND 120;
IN
#1. 查询员工的工种编号是 AD_VP,IT_PROG,AD_PRES中的一个的员工名和工种编号
SELECT
last_name,
job_id
FROM
employees
WHERE
job_id IN (
"AD_VP",
"IT_PROG",
"AD_PRES");
IS NULL 和 IS NOT NULL
#1. 查询没有奖金的员工名和奖金率
SELECT last_name,commission_pct
FROM employees WHERE commission_pct IS NULL;
SELECT last_name,commission_pct
FROM employees WHERE commission_pct IS NOT NULL;
<=>:安全等于
- 可以判断 NULL 和 普通值
SELECT last_name,commission_pct
FROM employees WHERE commission_pct <=> NULL;
边栏推荐
- [Qunhui] command line acme SH automatically apply for domain name certificate
- MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
- Alipay failed to verify the signature (sandbox test indicates fishing risk?) [original]
- Capture packets (Wireshark)
- TP5 distinct method paging problem
- Resolve PHP is not an internal or external command
- 2021/11/6-burpsuit packet capturing and web page source code modification
- Your requirements could not be resolved
- 35 year old programmer fired Luna millions of assets and returned to zero in three days. Netizen: it's the same as gambling
- CTF serialization and deserialization
猜你喜欢

OSS CDN alicloud configuration method

CDN with OSS acceleration

企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?

Performance test comparison between PHP framework jsnpp and thinkphp6

SQL related knowledge - DDL
![[QT] dialog box](/img/ca/e65a0c167a4509f7c6a241870f6a32.png)
[QT] dialog box

Construction of art NFT trading platform | NFT mall

Install dbeaver and connect Clickhouse

Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
![Notes on enterprise wechat development [original]](/img/66/cd83f4f86b7c42921db45f07957c15.jpg)
Notes on enterprise wechat development [original]
随机推荐
[Qunhui] no port access (reverse proxy + intranet penetration)
一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)
PHP inherited in class return does not work
[Qunhui] import certificate
A troubleshooting of website crash due to high CPU
Solution to composer error could not find package
Group by and order by are used together
Oracle data pump table
CTF serialization and deserialization
Thinkphp6 implements a simple lottery system
Computer network high frequency interview questions
Use shell script to analyze system CPU, memory and network throughput
Performance test comparison between PHP framework jsnpp and thinkphp6
How does virtual box virtual machine software accelerate the network speed in the virtual system?
2021-01-31
Nailing open platform - applet development practice (nailing applet client)
Tp6 controller does not exist: app\index\controller\index
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
Resolve PHP is not an internal or external command
Report on demand situation and development trend of China's OTC industry from 2022 to 2028