DQL查询数据语言(MySQL)
2021/4/8 19:26:21
本文主要是介绍DQL查询数据语言(MySQL),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
DQL查询数据语言(重点)
Select (核心)
1.查询所有字段
select * from `表名`;
2.查询指定字段
select `字段1`,`字段2` from `表名`;
3.给结果取一个名字
select `字段1` as 名字1,`字段2` as 名字2 from `表名`;
4.去重distinct
select distinct `字段` from `表名`;(例:select distinct `age` from `students`;)
where条件语句
检索符合条件的值
运算符 | 语法 | 描述 |
and && | a and b / a && b |
逻辑与 两个都为真结果为真 |
or || | a or b / a || b | 逻辑或 一个为真结果为真 |
not ! | is not / != | 逻辑非 真假反转 |
select `classhour` from `subject` where `classhour` = 110 and `gradeid` =1;
select `classhour` from `subject` where `classhour` !=110; (select `classhour` from `subject` where not `classhour`=110;)
模糊查询
运算符 | 语法 | 描述 |
is null | a is null | 如果a为null,结果为真 |
is not null | a is not null | 如果a不为null,结果为真 |
between | a between b and c | 若a在b和c之间,结果为真 |
like | a like b | SQL匹配,如果a匹配b,结果为真 |
in | a in (a1,a2,a3...) | a在数列内,结果为真 |
1.like例子
查询表中姓胡的同学 like结合(%代表任意字符,_代表一个字符)
select `name` from `students` where `name` like '胡%';
查询姓胡的同学,名字后面只有一个字
select `name` from `students` where `name` like '胡_';
查询姓胡的同学,名字后面有两个字
select `name` from `students` where `name` like '胡__';
查询名字中间有太字的同学 %太%
select `name` from `students` where `name` like '%太%';
2.in例子
查询学号为10001,10002,10003的同学
select `name` from `students` where id in (10001,10002,10003);
3.null和not null
查询班级号为空的人
select `name` from `students` where `gradid` is null;
查询学科表内学时在100和140之间的人
select `classhour` from `subject` where `classhour` between 100 and 140;
这篇关于DQL查询数据语言(MySQL)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享
- 2024-02-22docker mysql 5.7
- 2024-02-18从 20 多套 MySQL 到 1 套 TiDB丨骏伯网络综合运营管理平台应用实践
- 2024-02-07mysql 外键索引入门介绍,为什么工作中很少有人使用?