二、sql基础:where和排序--【Oracle数据库】

二、条件限制和排序

1.条件

where
常用:
范围:
select * from student where classid between 01 and 09;

在一个集合范围内:
select * from student where classid in (01,03,04);–>查询的是01、03、04班的学生信息。

模糊查询
select * from student s where s.name like ‘%xu%’;

补充:
% 表示任意字符
_ 表示占一位的任意字符

判断NULL
select * from student s where s.job is null;
注意不能使用=NULL


2.多条件查询

同时满足多个条件
select * from student s where s.classid = 01 and s.stuid = 98;

满足一个条件即可
用or


3.关键字:not
select * from student s where s.job is not null;
select * from student where classid not in (01,03,04);

4.关键字:escape

当我们要查询的条件包含通配符怎么办?
例如:remark字段某一行:a%b
我们要查询remark字段有%这个字符的所有记录。
select * from student where remark like ‘%\%%’ escape ‘\’;
使用escape表示’\’后面的字符是一个实实在在的字符,不再具有通配符的意义。(当然’\’可以变成’k’这种任意字符,escape其实是指定一个转义字符。)


5.排序
select * from student where classid = 9 order by grade;  --->升序排列
select * from student where classid = 9 order by grade desc;  --->降序排列

猜你喜欢

转载自blog.csdn.net/qq_29668759/article/details/79965167
今日推荐