当前位置: 代码网 > it编程>数据库>Mysql > 使用SQLyog的sql条件查询方式

使用SQLyog的sql条件查询方式

2024年05月26日 Mysql 我要评论
1. 等值判断(=)#查询符合条件的数据select employee_id,first_name,salaryfrom t_employeeswhere salary = 10000;2. 不等值判

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;

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com