DQL语言的学习(二)

本文深入探讨了DQL语言中的条件查询技术,包括条件表达式、逻辑表达式、模糊查询、NULL值处理等多种查询方式。通过具体实例,讲解了如何使用LIKE、BETWEEN AND、IN、IS NULL等关键字进行高效的数据筛选。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DQL语言的学习(二)

二、条件查询

语法:

SELECT A FROM table_name WHERE B=C;

(一)条件表达式

条件运算符 > , < , = , <> , >= , <=,<=>(安全等于)

select * from students where age>13;

(二)逻辑表达式

逻辑运算符&&,||,!,and,or,not

select studennt_name from students where student_grade>1 and student_grade<4;

(三)模糊查询

1.like
与通配符搭配使用,%表示任意多个字符(包括0个),_表示人以单个字符

select * from students where student_name like '%a%';
select * from students where student_name like '__n_l';
select student_name from students like '_#_%' escape '#';//将_转义为普通字符,用escape规定#为转移符号

2.between and
前后两个临界值也包含在内,且不能调换

select * from students where student_age between 12 and 14; 

3.in
用于判断字段值是否属于括号中的一项,括号中的值必须统一,in相当于等于号,因此不支持通配符。

select student_name from students where student_id in ('214617','1946','8773256414');

4.is null,is not null
不等号不能判断null值

select student_name,bonus from students where bonus is not null;

5.安全等于
可以比较值,也可以判断null值,但可读性差

select student_name,bonus from students where bonus <=> 1000;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值