1.查询没有佣金且工资低于1000元的职员名字,工资额和所在部门号
SQL> select ename,sal,deptno from emp where comm is null and sal<1000;
这题并不难主要是comm is null而不是0这一点需要注意
2.查询平均工资大于1900元的部门的工资总额,职员人数和平均工资。*/
这是我自己写的:没有用到group by having语句所以弄出这么多的select导致select语句复杂化了
SQL> select sum(sal),count(*),avg(sal) from emp,(select * from (select deptno,av
g(sal) avg from emp group by deptno) e where e.avg>1900) m where emp.deptno=m.de
ptno group by m.deptno;
查询之后用这种方式非常间接,碰到分组而且还有分组条件的使用group by having语句
SQL> select avg(sal),count(*),sum(sal),deptno from emp group by deptno having avg(sal)>1900;
3.查询1981年6月30日之后受雇的职员的最高报酬(包括工资和佣金)。*/
SQL> select max(sal+comm) from emp where hiredate>to_date(19810630,'yyyy-MM-dd');
这里知道了max函数相应的还有min函数 还有一个是to_date函数,前面是日子值,后面参数是日期格式,
4./*查询能获得虹利(即在BONUS表中存在)的推销员的名字*/
SQL> select e.ename from emp e,bonus where e.job='SALESMAN' and bonus.sal is not
null;
这句没查询出来结果
5./*查询部门10中所有所赚的工资在最高一级的职员名字,工资及受雇日期。
SQL> select e.ename,e.sal,e.hiredate from emp e,(select max(losal) l,max(hisal)
h from salgrade) m where e.deptno=10 and e.sal between m.l and m.h;这个是我写的
参考的答案貌似比较复杂也贴出来:
select ename ,sal,hiredate from emp
where deptno=10 and sal<=(
select hisal from salgrade
where grade=(
select max(grade)from salgrade
))and sal>=(select losal from salgrade
where grade=(
select max(grade)from salgrade
)
)