DQL( 数据查询语言)

1. 基本查询

select * from 表名;

select 字段,字段2,... from 表名;

select * from 表名 where 筛选条件;

select 字段,字段2,... from 表名 where 筛选条件;

2. 范围查询

select * from emp where sal = 3000; 
select * from emp where sal != 3000;
select * from emp where sal >= 3000;
select * from emp where sal <= 3000;
select * from emp where sal > 3000;
select * from emp where sal < 3000;
select * from emp where sal <> 3000;   -- 不等于

3. 包含查询

select * from emp where deptno in(10,20);

4. 闭区间查询

select * from emp where sal between 950 and 2450;

5. 逻辑查询

逻辑查询 not>and>or and:遇假则假 or:遇真则真 not:取反

and:遇假则假  or:遇真则真  not:取反
--查询emp表中20号部门,薪资大于2000的员工的信息
select * from emp where deptno=20 and sal>2000;
--查询emp表中,岗位是SALESMAN或者ANALYST的员工信息
select * from emp where job='SALESMAN' or job='ANALYST';
--查询不是老板的员工信息
select * from emp where not job='PRESIDENT';

6. 空值查询

is null 为空 is not null 不为空

select * from emp where comm is null;
select * from emp where comm is not null;

7. 模糊查询

通配符:

_:代表这个位置只有1个字符;

%:代表这个位置有0个或者无数个字符;

--查询emp表格员工的工种是以M开头的员工信息
select * from emp where job like'M%';
--查询员工姓名倒数第2个字母是E的员工信息
select * from emp where ename like'%E_';
  • 查询表格中带有%的数据 -- escape

需要把%或者_这个通配符转义称为普通的字符串

--查询表格中带有%的数据
select * from op9 where n like'%\%%' escape'\';
--查询表格中带有_的数据
select * from op9 where n like'%\_%' escape'\';
相关推荐
达梦产品与服务1 小时前
SQLark 数据迁移|断点续迁已上线(Oracle-达梦)
数据库·oracle·数据迁移·断点续迁
Su米苏3 小时前
undo log、redo log、bin log是什么
mysql
北极熊kw3 小时前
CentOS 9/10 Stream / RockyLinux 8 上安装 Oracle database 19c
数据库·oracle·centos
猫猫的小茶馆5 小时前
基于嵌入式linux的数据库:SQLite
linux·服务器·c语言·数据库·单片机·ubuntu·sqlite
一个假的前端男5 小时前
express(node ORM) 使用 Winston 记录日志 及数据库保存日志
android·数据库·express
luoluoal5 小时前
java项目之基于ssm的线上旅游体验系统(源码+文档)
java·mysql·mybatis·ssm·源码
浪九天5 小时前
MySQL 数据库基础详细解释和示例
数据库·mysql
怡~5 小时前
Golang适配达梦数据库连接指定模式
开发语言·数据库·golang
小马爱打代码6 小时前
MySQL - 一条查询语句是怎么执行的?
数据库·mysql
yqcoder6 小时前
Express + MongoDB 实现用户登出
数据库·mongodb·express