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 <=40000;
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 <40000 then 'b' when salary>20000 and salary <30000 then 'c' when salary>10000 and salary <20000 then 'd' else 'e' end as '薪资级别' from t_employees;
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论