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;
相关推荐
fengxin_rou15 分钟前
Redis 从零到精通:第一篇 初识redis
数据库·redis·缓存
爱学习的阿磊21 分钟前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
m0_7369191025 分钟前
Python面向对象编程(OOP)终极指南
jvm·数据库·python
OceanBase数据库官方博客34 分钟前
滔搏基于OceanBase实现 15TB到0.9TB“无痛切换”与“系统瘦身”
数据库·oceanbase·分布式数据库
Jess0739 分钟前
MySQL内置函数
数据库·mysql
OceanBase数据库官方博客41 分钟前
爱奇艺基于OceanBase实现百亿级卡券业务的“单库双擎”架构升级
数据库·架构·oceanbase·分布式数据库
weixin1997010801644 分钟前
锦程物流item_get - 获取详情接口对接全攻略:从入门到精通
数据库·python
AC赳赳老秦1 小时前
DeepSeek 辅助科研项目申报:可行性报告与经费预算框架的智能化撰写指南
数据库·人工智能·科技·mongodb·ui·rabbitmq·deepseek
2501_927773071 小时前
Linux系统编程——sqlite数据库
数据库
mahailiang1 小时前
codeblocks+wxWidgets Projects中引用第三方库(sqlite3)
数据库·sqlite·wxwidgets·codeblocks