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.授予新登 ...
随机推荐
- [转]【HTTP】Fiddler(二) - 使用Fiddler做抓包分析
本文转自:http://blog.csdn.net/ohmygirl/article/details/17849983 上文( http://blog.csdn.net/ohmygirl/articl ...
- NP完全问题 NP-Completeness
原创翻译加学习笔记,方便国人学习算法知识! 原文链接http://www.geeksforgeeks.org/np-completeness-set-1/ 我们已经找到很多很高效的算法来解决很难得问题 ...
- swfobject.js视频播放插件
在网页中经常会用到视频播放的功能,下面介绍一下swfobject.js的视频播放应用:html代码结构: <div id="video_content"></di ...
- 用Navicat更新数据库表中的某一字段
最近需要在A表中根据B表的某一值来进行排序输出,无奈SQL技术不够,不知道怎么连接才能达到目标,于是想到在A表中添加B表的目标值字段,然后通过更新A表从而使A表有目标字段,进而进行排名....够不够纠 ...
- HDU 5057 Argestes and Sequence --树状数组(卡内存)
题意:给n个数字,每次两种操作: 1.修改第x个数字为y. 2.查询[L,R]区间内第D位为P的数有多少个. 解法:这题当时被卡内存了,后来看了下别人代码发现可以用unsigned short神奇卡过 ...
- Codeforces Round #270 D Design Tutorial: Inverse the Problem --MST + DFS
题意:给出一个距离矩阵,问是不是一颗正确的带权树. 解法:先按找距离矩阵建一颗最小生成树,因为给出的距离都是最短的点间距离,然后再对每个点跑dfs得出应该的dis[][],再对比dis和原来的mp是否 ...
- Git版本控制工具(一)----git的安装及创建版本库
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- 【hibernate】<第二节>hibernate的一对多映射(基本类型)
所需工具与前文一致! 第一部分内容:基本类型的一对多(one to many) 以部门表与员工表为例: 目录结构: hibernate.cfg.xml内容 <?xml version=" ...
- Springmvc返回JSON乱码问号
@RequestMapping(value="/book/getBook.do", produces = "text/html;charset=UTF-8") ...
- javascript中的栈结构
1.栈的定义 栈是一种和列表类似的数据结构,可以用它来解决很多的编程问题,栈是一种高效的数据结构,因为数据只能在栈的顶端添加或者删除,所以这样的操作很快而且容易实现. 栈是一种特殊的列表,站内的元素只 ...