oracle练习题后15个
31,32题更正:
SQL> --31、 查询所有教师和同学的name、sex和birthday.
SQL> select sname, ssex, sbirthday from student
2 union all
3 select tname, tsex, tbirthday from teacher;
SNAME SSEX SBIRTHDAY
-------- ---- -----------
曾华 男 1977/9/1
匡明 男 1975/10/2
王丽 女 1976/1/23
李军 男 1976/2/20
王芳 女 1975/2/10
陆君 男 1974/6/3
李诚 男 1958/12/2
张旭 男 1969/3/12
王萍 女 1972/5/5
刘冰 女 1977/8/14
10 rows selected SQL> --32、查询所有“女”教师和“女”同学的name、sex和birthday.
SQL> select sname, ssex, sbirthday from student where ssex = '女'
2 union all
3 select tname, tsex, tbirthday from teacher where tsex = '女';
SNAME SSEX SBIRTHDAY
-------- ---- -----------
王丽 女 1976/1/23
王芳 女 1975/2/10
王萍 女 1972/5/5
刘冰 女 1977/8/14
SQL> --31、 查询所有教师和同学的name、sex和birthday.
SQL> select sname, ssex, sbirthday from student;
SNAME SSEX SBIRTHDAY
-------- ---- -----------
曾华 男 1977/9/1
匡明 男 1975/10/2
王丽 女 1976/1/23
李军 男 1976/2/20
王芳 女 1975/2/10
陆君 男 1974/6/3
6 rows selected SQL> select tname, tsex, tbirthday from teacher;
TNAME TSEX TBIRTHDAY
----- ---- -----------
李诚 男 1958/12/2
张旭 男 1969/3/12
王萍 女 1972/5/5
刘冰 女 1977/8/14 SQL> 32-32、查询所有“女”教师和“女”同学的name、sex和birthday.
2 ;
32-32、查询所有“女”教师和“女”同学的name、sex和birthday.
ORA-00900: 无效 SQL 语句 SQL> select sname ssex sbirthday from student where ssex = '女';
select sname ssex sbirthday from student where ssex = '女'
ORA-00923: 未找到要求的 FROM 关键字 SQL> select sname, ssex, sbirthday from student where ssex = '女';
SNAME SSEX SBIRTHDAY
-------- ---- -----------
王丽 女 1976/1/23
王芳 女 1975/2/10 SQL> select tname, tsex, tbirthday from teacher where tsex = '女';
TNAME TSEX TBIRTHDAY
----- ---- -----------
王萍 女 1972/5/5
刘冰 女 1977/8/14 SQL> --33、 查询成绩比该课程平均成绩低的同学的成绩表。
SQL> select degree from score where degree < (select avg(degree) from score);
DEGREE
------
75.0
68.0
76.0
64.0
78.0
79.0
6 rows selected SQL> --34、 查询所有任课教师的Tname和Depart.
SQL> select tname, depart from teacher;
TNAME DEPART
----- ----------
李诚 计算机系
张旭 电子工程系
王萍 计算机系
刘冰 电子工程系 SQL> --35 、 查询所有未讲课的教师的Tname和Depart.
SQL> select tname, depart from teacher where tname not in
2 (select tname from teacher te, score sc, course co where te.tno = co.tno and co.cno = sc.cno);
TNAME DEPART
----- ----------
刘冰 电子工程系 SQL> --36、查询至少有2名男生的班号。
select class from student where ssex = '男' group by class having count (1) >=2;
2
SQL> select class from student where ssex = '男' group by class having count (1) >=2;
CLASS
-----
95033
95031 SQL> --37、查询Student表中不姓“王”的同学记录。
SQL> select * from student where sname not in '王%';
SNO SNAME SSEX SBIRTHDAY CLASS
--- -------- ---- ----------- -----
108 曾华 男 1977/9/1 95033
105 匡明 男 1975/10/2 95031
107 王丽 女 1976/1/23 95033
101 李军 男 1976/2/20 95033
109 王芳 女 1975/2/10 95031
103 陆君 男 1974/6/3 95031
6 rows selected SQL> select * from student where sname not like '王%';
SNO SNAME SSEX SBIRTHDAY CLASS
--- -------- ---- ----------- -----
108 曾华 男 1977/9/1 95033
105 匡明 男 1975/10/2 95031
101 李军 男 1976/2/20 95033
103 陆君 男 1974/6/3 95031 SQL> --38、查询Student表中每个学生的姓名和年龄。
SQL> --select sysdtaeselect sbirthday from student;
SQL>
SQL> --
SQL> select max(sbirthday) from student;
MAX(SBIRTHDAY)
--------------
1977/9/1 SQL> --39、查询Student表中最大和最小的Sbirthday日期值。
SQL> select min(sbirthday) from student;
MIN(SBIRTHDAY)
--------------
1974/6/3 SQL> --40、以班号和年龄从大到小的顺序查询Student表中的全部记录。
SQL> select * from student order by class desc, sbirthday;
SNO SNAME SSEX SBIRTHDAY CLASS
--- -------- ---- ----------- -----
107 王丽 女 1976/1/23 95033
101 李军 男 1976/2/20 95033
108 曾华 男 1977/9/1 95033
103 陆君 男 1974/6/3 95031
109 王芳 女 1975/2/10 95031
105 匡明 男 1975/10/2 95031
6 rows selected SQL> --41、查询“男”教师及其所上的课程。
SQL> select tname, cname from teacher te, course co where te.tno = co.tno and te.tsex = '男';
TNAME CNAME
----- ----------
李诚 操作系统
张旭 数字电路 SQL> --42、查询最高分同学的Sno、Cno和Degree列。
SQL> select sno, cno, degree from score where degree >= all (select degree from score);
SNO CNO DEGREE
--- ----- ------
103 3-105 92.0 SQL> --43、查询和“李军”同性别的所有同学的Sname.
SQL> select sname from student where ssex = (select ssex from student where ssname = '李军');
select sname from student where ssex = (select ssex from student where ssname = '李军')
ORA-00904: "SSNAME": 标识符无效 SQL> select sname from student where ssex = (select ssex from student where sname = '李军');
SNAME
--------
曾华
匡明
李军
陆君 SQL> --44、查询和“李军”同性别并同班的同学Sname.
SQL> select sname from student where ssex = (select ssex from student where sname = '李军') and class = (select class from student where sname = '李军');
SNAME
--------
曾华
李军 SQL> --45、查询所有选修“计算机导论”课程的“男”同学的成绩表。
SQL> select sname, degree from student st, score sc, course co where st.sno = sc.sno and sc.cno = co.cno and co.cname ='计 算机导论'
2 and ssex = '男';
SNAME DEGREE
-------- ------
曾华 78.0
匡明 88.0
李军 64.0
陆君 92.0 SQL> --20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。 SQL> select * from score where (degree < any(select degree from score)) and sno in(select sno from score group by sno having count(1) > 1);
SNO CNO DEGREE
--- ----- ------
101 3-105 64.0
101 6-166 85.0
105 3-105 88.0
105 3-245 75.0
109 3-105 76.0
109 3-245 68.0
103 3-245 86.0
108 3-105 78.0
108 6-166 81.0
107 3-105 91.0
107 6-166 79.0
11 rows selected SQL> --38、查询Student表中每个学生的姓名和年龄。
SQL> select sname, trunc(((months_between(sbirthday , (select trunc(sysdate) from dual))) / (-12)), 0) as 年龄 from student;
SNAME 年龄
-------- ----------
曾华 38
匡明 40
王丽 39
李军 39
王芳 40
陆君 41
6 rows selected
oracle练习题后15个的更多相关文章
- mysql数据库迁移到oracle数据库后 如何删除相同的数据
mysql数据库迁移到oracle数据库后 如何删除相同的数据 首先搞清楚有多少数据是重复的 select pid from product group by pid having count(pid ...
- 插入Oracle数据库后返回当前主键id
最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...
- oracle练习题
题干:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 建表后数据如下: SQL> select * from ...
- oracle登录后无法使用,显示Connected to an idle instance
1.登录情况: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul ...
- 【Java EE 学习 28 下】【Oracle面试题2道】【Oracle练习题3道】
一.已知程序和数据 create table test1 (id int primary key, name ), money int); ,); ,); ,); ,); 要求根据下图写出相应的sql ...
- oracle安装后登录
运行 sqlplus回车 longon as sysdba回车 回车 这样就可以登录了. SQL>create user username identified by password; SQL ...
- entity framework 连接 oracle 发布后出现的问题(Unable to find the requested .Net Framework Data Provider)
用entity framework 搭建的一个windows 程序,在vs中用oracle 的ODT 工具连接oracle数据库,昨天发布后出现下面一个错误, System.ArgumentExcep ...
- MySQL被Oracle并购后的409个日日夜夜
2009年4月20日,Oracle并购了Sun,这也意味着MySQL归属到甲骨文的旗下.四百多天过去了,究竟这场并购结局如何?请看本文. 去年对Sun的收购,让甲骨文顺利的将一个潜在的对手MySQL收 ...
- 第一安装oracle数据库后,需要创建一个用户,给用户解锁并赋予权限
1.第一次安装oracle数据库应该做的事情. 注: 1.安装oracle后需要创建用户,连接数据库,(注意数据库名,还有好像后面的 ":"也有影响) 2.解锁用户, 3.授予新登 ...
随机推荐
- 【Android UI设计与开发】6.底部菜单栏(三)使用Fragment+PopupWindow仿QQ空间最新版底部菜单栏
直接看栗子吧,效果基本实现,界面微调和弹窗的优化,去做的话会很耗时说,暂时就酱紫了.上传效果动态图太大了,直接手机截图的效果图如下: 至于代码的实现主要就是自定义的菜单栏,和用 PopupWindow ...
- Network client/server
<Beginning Linux Programming_4th> chapter 15 Sockets 1 A simple local client/server 1) clie ...
- gym101090 I Painting the natural numbers
题目地址:http://codeforces.com/gym/101090 题目: The H&H company currently develops AI (artificial inte ...
- DoTween(HOTween V2) 教程
DoTween资料 官方网站:http://dotween.demigiant.com/ 下载地址:http://dotween.demigiant.com/download.php 快速开始:htt ...
- zepto.js 源码解析
http://www.runoob.com/w3cnote/zepto-js-source-analysis.html Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jqu ...
- 025医疗项目-模块二:药品目录的导入导出-HSSF导入类的封装
上一篇文章提过,HSSF的用户模式会导致读取海量数据时很慢,所以我们采用的是事件驱动模式.这个模式类似于xml的sax解析.需要实现一个接口,HSSFListener接口. 原理:根据excel底层存 ...
- 浏览器默认样式(User Agent Stylesheet)
原文:http://www.zjgsq.com/898.html 不同浏览器对于相同元素的默认样式并不一致,这也是为什么我们在CSS的最开始要写 * {padding:0;marging:0}: 不过 ...
- SQL2008安装后激活方式以及提示评估期已过解决方法(转)
第一步:进入SQL2008配置工具中的安装中心第二步:再进入维护界面,选择版本升级第三步:进入产品密钥,输入密钥第四步:一直点下一步,直到升级完毕.SQL Server 2008 Developer: ...
- linux 高级编程之库的使用
一.静态库与动态库 静态库: .a .lib 动态库: .so .dll 差别(静态库中的代码在链接时就已经复制到可执行文件中,执行时不再依赖库,不会自动使用升级后的库,需要重新产生可执行文件. 动态 ...
- text/html与text/plain有什么区别?
MIME是服务器通知客户机传送文件是什么类型的主要方法,客户机浏览器也通过MIME告诉服务器它的参数. 在网上,如果接收到的文件没有MIME头,就默认它为HTML格式.但这样也不好,因为当MIME的包 ...