# 查询表中为null的数据SELECT last_name,salary,commission_pct
FROM employees
WHERE commission_pct ISNULL;# 查询表中为null的数据SELECT last_name,salary,commission_pct
FROM employees
WHERE commission_pct ISNOTNULL;# 查询表中并不为null的数据SELECT last_name,salary,commission_pct
FROM employees
WHERE ISNULL(commission_pct);
# 查询工资在6000到8000的员工工资SELECT employee_id,last_name,salary
FROM employees
WHERE salary BETWEEN6000AND8000;
IN (SET) \ NOT IN (SET)
#查询部门为10,20,30的员工信息SELECT last_name,salary,department_id
FROM employees
WHERE department_id IN(10,20,30);#查询部门不为10,20,30的员工信息SELECT last_name,salary,department_id
FROM employees
WHERE department_id NOTIN(10,20,30);
LIKE 模糊查询
# % : 代表不确定个数的字符# 查询last_name中包含字符包含‘a’的员工信息SELECT last_name
FROM employees
WHERE last_name LIKE'%a%';# 查询last_name中包含字符以‘a’开头的员工信息SELECT last_name
FROM employees
WHERE last_name LIKE'a%';# 查询last_name中包含字符包含‘a’且包含字符‘e’的员工信息SELECT last_name
FROM employees
WHERE last_name LIKE'%a%'AND last_name LIKE'%e%';# -:代表一个不确定的字符# 查询第2个字符是‘a’的员工信息SELECT last_name
FROM employees
WHERE last_name LIKE'_a%';# 查询第2个字符是‘_’第3个字符是‘a’的员工信息# 需要转义字符:\SELECT last_name
FROM employees
WHERE last_name LIKE'_\_a%';
REGEXP \ RLIKE
# REGEXP \ RLIKE :正则表达式
逻辑运算符
逻辑运算符: OR (||)、AND (&&)、 NOT (!)、 XOR
# OR AND (AND优先级高于OR)SELECT last_name,salary,department_id
FROM employees
# WHERE department_id = 10 OR department_id = 20;# WHERE department_id = 10 AND department_id = 20;WHERE department_id =50AND salary >6000;# NOTSELECT last_name,salary,department_id
FROM employees
# WHERE salary NOT BETWEEN 6000 AND 8000;# WHERE commission_pct IS NOT NULL;WHERENOT commission_pct <=>NULL;# XOR: 追求”异“SELECT last_name,salary,department_id
FROM employees
WHERE department_id =50XOR salary >6000;