MySQL在基础查询基础上升级到条件查询

条件查询

语法

sql 复制代码
select
查询列表
from
表名称
where
筛选条件

1. 按照条件表达式来筛选

sql 复制代码
条件运算符: > , < , = , != / <>(MYSQL特有的不等号) , >= , <=

2.按照逻辑表达式筛选

sql 复制代码
逻辑运算符:支持java的写法(&& , || , ! ), 但推荐使用mysql自己的(and , not , or)

3.模糊查询

sql 复制代码
like , between...and , in , is null

4.看条件表达式

案例:查询员工工资大于1200的员工有哪些:

sql 复制代码
select * from employees where salary > 12000;

案例:查询部门编号不等于90号的员工名和部门编号:

sql 复制代码
select concat(last_name,first_name) as 姓名 , department_id
from employees where department_id <> 90;

5.逻辑表达式

sql 复制代码
逻辑运算符主要作用:链接表达式
&&和and : 全式true结果才式true;
||和or: 只要有一个true结构就式true;
!和not: 取反;

案例:工资在10000到20000之间到员工名,工资和奖金

sql 复制代码
select last_name,salary,commission_pct
from employees where salary>=10000 and salary<=20000;
sql 复制代码
select * from employees where (department_id<90 and department_id>110) or salary>15000;
select * from employees where not(department_id>=90 and department_id<=110) or salary>15000;
相关推荐
xxjj998a41 分钟前
Laravel6.x核心特性全解析
数据库·mysql·adb
m0_748554818 小时前
golang如何实现用户订阅偏好管理_golang用户订阅偏好管理实现总结
jvm·数据库·python
早日退休!!!9 小时前
《数据结构选型指南》笔记
数据结构·数据库·oracle
xcLeigh9 小时前
KES数据库性能优化实战
数据库·sql·性能优化·sql优化·数据性能
阿正呀9 小时前
Redis怎样实现本地缓存的高效失效通知
jvm·数据库·python
yoyo_zzm9 小时前
Laravel9.x新特性全解析
数据库·mysql·nginx
2501_901200539 小时前
mysql如何设置InnoDB引擎参数_优化innodb_buffer_pool
jvm·数据库·python
m0_4954964110 小时前
mysql处理复杂SQL性能_InnoDB优化器与MyISAM差异
jvm·数据库·python
forEverPlume11 小时前
PHP怎么使用Eloquent Attribute Composition属性组合_Laravel通过组合构建复杂属性【方法】
jvm·数据库·python
2301_8092047011 小时前
mysql在docker容器中如何部署_利用docker-compose快速启动
jvm·数据库·python