|
表emp(deptno,ename,sal),表salgrade(grade,losal,hisal),表dept(deptno,..);
1,查出每组人员的平均工资:
select avg(sal) from emp group by deptno;
2,查看每组平均工资的级别:
select t.avg_sal,grade,t.deptno from emp s
join (select avg(sal) avg_sal ,deptno from emp group by ) t
on s.avg_sal between t.losal and t.hisal;
3,原来的等值连接:
select ename, dname from emp, dept where emp.deptno = dept.deptno;
新语法的等值连接:
select ename, dname from emp join dept on ( emp.deptno = dept.deptno);
等值连接的简单的写法:
select ename, dname from emp join dept using (deptno)
using (deptno) --> 是说我这个表的deptno等于你这个表的deptno
* using 的用法不推荐使用 --> 两张表中要有相同的字段,类型必须相同
|
|