oracle数据库(四)

oracle高级查询

1.别名 AS

SELECT s.SNO AS 学号, s.sname AS 姓名,s.ssex AS 性别 FROM STUDENT s

2.消除重复列 DISTINCT

SELECT DISTINCT s.SNO AS 学号, s.sname AS 姓名,s.ssex AS 性别 FROM STUDENT s

3.模糊查询 LIKE

SELECT * FROM STUDENT s WHERE s.sname LIKE '小_'

_ 表示: 1个字符 %表示多个字符

4.范围查询 BETWEEN

SELECT * FROM STUDENT s WHERE s.sno BETWEEN 1 AND 2

5.空值查询 IS NOT NULL

SELECT * from student WHERE sclass IS NOT NULL;

6.子查询

select * from STUDENT where sid=(select sid from student where sname='小明');

7.分组查询 GROUP BY

select SSEX ,count(*) AS 总人数 from STUDENT GROUP BY SSEX ;

8.HAVING

select SSEX,count(*) AS 总人数 from STUDENT GROUP BY SSEX HAVING count(*) >1

HAVING 和 WHRER 的区别 :
having子句和group by一起使用,紧跟在group by的后边,having子句可以使用结果集中的列,也可以使用聚合函数(max、min、count、sum、svg)。having的作用是对分组后的结果进行过滤。这里在提一下where,where是对每一行进行过滤的,查询出符合where条件的每一行。having是对查询出结果集分组后的结果进行过滤。

9.排序 ORDER BY

select * from student order by sid asc;

asc:升序 (默认) desc:降序 一般放在最后

10.交集 UNION

select sid from student union all  select sname from student

11.并集 INTERSECT

select * from student intersect select * from student1

12.差集 MINUS

select * from student MINUS select * from student1

13.多表查询
未完待续….

你可能感兴趣的:(oracle)