1. 等值判断(=)
#查询符合条件的数据 SELECT employee_id,first_name,salary FROM t_employees WHERE salary = 10000;
2. 不等值判断(>、=、 )和逻辑判断(and、or、not)
!=和都是不等于
# 查询员工的工资再10000~40000之间的员工信息(编号,名字,薪资) SELECT employee_id,first_name,salary FROM t_employees WHERE salary >= 10000 AND salary
3.区间判断(between and)
#查询员工的薪资在10000~50000之间的员工信息(编号,名字,薪资) SELECT employee_id,first_name,salary FROM t_employees WHERE salary BETWEEN 10000 AND 50000;
4. NULL值判断(IS NULL、IS NOT NULL)
#查询没有提成的员工信息(编号,名字,薪资,提成) SELECT employee_id,first_name,salary,commission_pct FROM t_employees WHERE commission_pct IS NULL;
5. 枚举查询
#查询部门编号为90、30的员工信息(编号,名字,薪资,部门编号) SELECT employee_id,first_name,salary,department_id FROM t_employees WHERE department_id IN(90,30);
6. 模糊查询
LIKE_ (单个任意字符) 列名 LIKE ‘张_' LIKE % (任意长度的任意字符) 列名 LIKE ‘张%'
#查询名字已“L”开头的员工信息(编号,名字,薪资,部门编号) SELECT employee_id,first_name,salary,department_id FROM t_employees WHERE first_name LIKE 'L%'; #查询名字已“L”开头并且长度为3的员工信息(编号,名字,薪资,部门编号) SELECT employee_id,first_name,salary,department_id FROM t_employees WHERE first_name LIKE 'L__';
7.分支结构查询
CASE WHEN 条件1 THEN 结果1 WHEN 条件2 THEN 结果2 WHEN 条件3 THEN 结果3 ELSE 结果4 END
#查询员工信息(编号,名字,薪资,薪资级别) SELECT employee_id,first_name,salary, CASE WHEN salary>40000 THEN 'A' WHEN salary>30000 AND salary 20000 AND salary 10000 AND salary
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT俱乐部。