SQL操作符
算术操作符:+加,-减,*乘,/除
比较操作符:
- <,>,=,!=,<>,<=,>=
常用的判断,<>和!=相同 - between $lower_val$ and $hight_val$
between .. and.. 包括两端
复制--查询20<=age<=21的学生数据
select * from student where age between 20 and 21
- not between $lower_val$ and $hight_val$
与上面相反 - in(值列表), not in(值列表)
复制--查询年龄是20或21的学生数据
select * from student where age in (20,21)
- is null, IS NOT NULL
是否为空 - like, not like
匹配 ( 通配 )操作符:%匹配任意多个字符;_匹配任意单个字符;- 可以使用escape '$'指定转义字符,默认是""
复制--姓氏为张的学生,张二,张三,张四五都符合条件
select * from student where name like '张%';
--名字含有三的
select * from student where name like '%三%';
--姓氏为张,名字只有两个字的学生
select * from student where name like '张_';
--名字中包含%号的
select * from student where name like '%\%%' escape '\' ;
逻辑操作符: AND, OR, NOT
与,或
连接操作符: ||
复制-- 查询student表中你的num和name列,并把这两列显示出来
select num||,||name from student
集合(查询的结果集)操作符
下一章《高级查询》再讲
a)UNION 联合,将两个查询结果拼起来
b)UNION ALL 联合所有,多出现重复行
c)INTERSECT 交集
d)MINUS 减集
本文详细介绍了SQL中的各种操作符,包括算术操作符、比较操作符、逻辑操作符等。并通过实例展示了如何使用这些操作符进行数据筛选,如使用between...and...进行范围查询,使用like进行模糊匹配等。
2026

被折叠的 条评论
为什么被折叠?



