- 论坛徽章:
- 0
|
oracle 查询语句
1.列出平均工资大于1500的所有工作类型 select distinct job from emp having avg(sal)>1500 group by job; WHERE子句不能用于限制分组函数。在ORACLE中您可以使用HAVING子句来限制分组函数。 当使用了HAVING子句时,ORACLE系统处理的顺序如下: 1. 首先对数据行(记录)进行分组 2. 把所得到的分组应用于分组函数 3. 最后显示满足HAVING子句所指定条件的结果 HAVING clauses and WHERE clauses can both be used in a single query. Conditions in the HAVING clause logically restrict the rows of the result only after the groups have been constructed 2.列出2005年12月5日前入职的所有员工 select * from emp where hiredate>=to_date('2005-12-05','yyyy-mm-dd') 3.对于emp,列出各个部门中平均工资高于本部门平均水平的员工数和部门号,按部门号排序 select deptno,count(*) from (select * from emp where sal> (select avg(sal) from emp)) group by deptno order by deptno SELECT 语句有下列其中一种错误: * 标识的表达式和列函数包含在 SELECT 子句、HAVING 子句或 ORDER BY 子句 中,但无 GROUP BY 子句 * 标识的表达式包含在 SELECT 子句、HAVING 子句或 ORDER BY 子句中,但不在 GROUP BY 子句中。 4.查询001课程比002课程成绩高的所有学生的学号; select a.sid from (select sid,score from sc where cid =001)a,(select sid,score from sc where cid=002)b where a.score>b.score and a.sid = b.sid; 5.查询平均成绩大于60分的同学的学号和平均成绩; select sid, avg(score) from sc group by sid having avg(score)>60; 6.select student.sid,student.sname,count(sc.cid),sum(score) from student left join sc on student.sid=sc.sid group by student.sid,sname 7.select student.sid,student.sname from student left join sc on student.sid= sc.sid left join course on sc.cid = course.cid where course.tid !=(select tid from teacher where tname='小李'); |
|