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.授予新登 ...
随机推荐
- openPOWERLINK开源POWERLINK协议栈说明文档中文非官方翻译
GitBook分享,翻译进行中:https://winshton.gitbooks.io/openpowerlink-stack-cn/content/
- NOIP2008 普及组T2 排座椅 解题报告-S.B.S
题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳.同学 ...
- 【温故而知新-Javascript】使用 Window 对象
1. 获取 Window 对象 可以用两种方式获得Window对象.正规的HTML5方式是在Document对象上使用defaultView属性.另一种是使用所有浏览器都支持的全局变量window . ...
- c++仿函数 functor
内容整理自国外C++教材 先考虑一个简单的例子:假设有一个vector<string>,你的任务是统计长度小于5的string的个数,如果使用count_if函数的话,你的代码可能长成这样 ...
- web前端笔试题总结
em和rem的区别: 浏览器的默认字体高度是16px,1em=16px:大小可以自己设置调整,并且默认集成父级容器中文本的大小. rem是CSS3中新增的属性,默认情况下是文本尺寸的大小,不同的是它集 ...
- POJ 2387 Til the Cows Come Home --最短路模板题
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include ...
- HDU 1878 欧拉回路
并查集水题. 一个图存在欧拉回路的判断条件: 无向图存在欧拉回路的充要条件 一个无向图存在欧拉回路,当且仅当该图所有顶点度数都是偶数且该图是连通图. 有向图存在欧拉回路的充要条件 一个有向图存在欧拉回 ...
- leetcode: Path Sum II 迭代法
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- Spring AOP 注解和xml实现 --转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
- RabbitMQ 一二事 - 简单队列使用
消息队列目前流行的有三种 1. RabbitMQ 2. ActiveMQ 3. Kafka 这三种都非常强大,RabbitMQ目前用的比较多,也比较流行,阿里也在用 ActiveMQ是阿帕奇出品,但是 ...