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;
相关推荐
JIngJaneIL1 小时前
就业|高校就业|基于ssm+vue的高校就业信息系统的设计与实现(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·毕设·高校就业
CXH7281 小时前
nginx-file-server
运维·数据库·nginx
一 乐1 小时前
社区互助|社区交易|基于springboot+vue的社区互助交易系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·小区互助系统
q***57742 小时前
Spring Boot 实战:轻松实现文件上传与下载功能
java·数据库·spring boot
失散132 小时前
分布式专题——57 如何保证MySQL数据库到ES的数据一致性
java·数据库·分布式·mysql·elasticsearch·架构
YJlio2 小时前
进程和诊断工具速查手册(8.13):VMMap / DebugView / LiveKd / Handle / ListDLLs 一页式现场排障清单
数据库·笔记·学习
whn19772 小时前
达梦的dbms_lock在DSC中能用吗
数据库
未来之窗软件服务3 小时前
自建开发工具IDE(五)数据库预览——东方仙盟炼气期
数据库·ide·仙盟创梦ide·东方仙盟
1***Q7843 小时前
SQL Future
数据库·sql
hoiii1873 小时前
设置Redis在CentOS7上的自启动配置
数据库·redis·缓存