免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1176 | 回复: 1
打印 上一主题 下一主题

[Veritas NBU] oracle 查询语句 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-16 15:44 |只看该作者 |倒序浏览
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='小李');

论坛徽章:
0
2 [报告]
发表于 2012-03-16 15:44 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP