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.授予新登 ...
随机推荐
- [麦先生]LINUX常用命令总结
在系统的学习了如何搭建和利用LINUX进行开发后,我利用xMind这一个强大的bug级软件制作了LINUX常见操作命令汇总,但是由于博客园并不支持xMind格式文件的上传,我只能将其做成图片进行分解上 ...
- ok,今天讲讲linux的部分指令吧
Linux布置服务 cd 进入 ../ 上一层目录 sh shutdown.sh -------tomcat的关闭指令 sh startup.sh ------ ...
- 求次短路 codevs 1269 匈牙利游戏
codevs 1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Descriptio ...
- HDU 4121 Xiangqi --模拟
题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...
- SPOJ AMR10E Stocks Prediction --二分求和+矩阵快速幂
题意:给一个递推式S(n) = a1*S(n-1)+...+aR*S(n-R),要求S(k)+S(2k)+...+S(nk)的值. 分析:看到n的大小和递推式,容易想到矩阵快速幂.但是如何转化呢? 首 ...
- 解决-bash: lsb_release: command not found
今天想判断系统版本,没想到没有lsb_release,lsb_release是查看系统版本信息的工具.当然我们也可以用其他的命令来解决,但这个问题还是解决掉. 系统:centos 6.41.先检查有没 ...
- Java虚拟机工作原理详解 ( 二 )
首先这里澄清两个概念:JVM实例和JVM执行引擎实例,JVM实例对应了一个独立运行的Java程序,而JVM执行引擎实例则对应了属于用户运行程序的线程:也就是JVM实例是进程级别,而执行引擎是线程级别的 ...
- Python-操作Memcache、Redis、RabbitMQ、
Memcache 简述: Memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的.需要 ...
- Web的形式发布静态文件
Web的形式发布静态文件 虽然ASP.NET Core是一款"动态"的Web服务端框架,但是在很多情况下都需要处理针对静态文件的请求,最为常见的就是这对JavaScript脚本文件 ...
- Linux 网络编程四(socket多线程升级版)
//网络编程--客户端 #include <stdio.h> #include <stdlib.h> #include <string.h> #include &l ...