Oracle-连接和分组

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caoxuecheng001/article/details/85138197

学习新知识前先复习以前学过的知识

1、去重关键字:distinct

select distinct job from emp where comm is not null;//去重

2、日期函数

select * from emp where last_day(hiredate)-2=hiredate;//每个月倒数第三天雇佣的员工

 select * from emp where months_between(sysdate,hiredate)/12>12;//12年前雇佣的员工

接下来学习新的知识:

一:连接

先介绍Oracle特有的方式:

select * from emp e,dept d where e.deptno(+)=d.deptno;//Oracle特有的

扫描二维码关注公众号,回复: 4777614 查看本文章

再介绍SQL1999规范制定的SQL语句。

select * from emp right outer join dept on(emp.deptno=dept.deptno);

//右外连接,把右边表的数据都显示出来。右边的表里的null也要显示出来

二:统计函数

三分组

特别注意:在where子句中不能使用统计函数,分组之后还想再次过滤,就要用到having子句,也可以说having和group by是成对出现的。

 

 

猜你喜欢

转载自blog.csdn.net/caoxuecheng001/article/details/85138197