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;
相关推荐
一 乐4 分钟前
绿色农产品销售|基于springboot + vue绿色农产品销售系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·宠物
黄宝康11 分钟前
sqlyog密钥亲测有效
mysql
Codeking__12 分钟前
Redis初识——什么是Redis
数据库·redis·mybatis
YIN_尹13 分钟前
【MySQL】数据类型(上)
android·mysql·adb
k***19518 分钟前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring
程序员黄老师23 分钟前
主流向量数据库全面解析
数据库·大模型·向量·rag
Full Stack Developme39 分钟前
Redis 可以实现哪些业务功能
数据库·redis·缓存
rgeshfgreh1 小时前
Spring事务传播机制深度解析
java·前端·数据库
无名-CODING1 小时前
Java Spring 事务管理深度指南
java·数据库·spring
想唱rap1 小时前
MYSQL在ubuntu下的安装
linux·数据库·mysql·ubuntu