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个的更多相关文章

  1. mysql数据库迁移到oracle数据库后 如何删除相同的数据

    mysql数据库迁移到oracle数据库后 如何删除相同的数据 首先搞清楚有多少数据是重复的 select pid from product group by pid having count(pid ...

  2. 插入Oracle数据库后返回当前主键id

    最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...

  3. oracle练习题

    题干:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 建表后数据如下: SQL> select * from ...

  4. oracle登录后无法使用,显示Connected to an idle instance

    1.登录情况: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul ...

  5. 【Java EE 学习 28 下】【Oracle面试题2道】【Oracle练习题3道】

    一.已知程序和数据 create table test1 (id int primary key, name ), money int); ,); ,); ,); ,); 要求根据下图写出相应的sql ...

  6. oracle安装后登录

    运行 sqlplus回车 longon as sysdba回车 回车 这样就可以登录了. SQL>create user username identified by password; SQL ...

  7. entity framework 连接 oracle 发布后出现的问题(Unable to find the requested .Net Framework Data Provider)

    用entity framework 搭建的一个windows 程序,在vs中用oracle 的ODT 工具连接oracle数据库,昨天发布后出现下面一个错误, System.ArgumentExcep ...

  8. MySQL被Oracle并购后的409个日日夜夜

    2009年4月20日,Oracle并购了Sun,这也意味着MySQL归属到甲骨文的旗下.四百多天过去了,究竟这场并购结局如何?请看本文. 去年对Sun的收购,让甲骨文顺利的将一个潜在的对手MySQL收 ...

  9. 第一安装oracle数据库后,需要创建一个用户,给用户解锁并赋予权限

    1.第一次安装oracle数据库应该做的事情. 注: 1.安装oracle后需要创建用户,连接数据库,(注意数据库名,还有好像后面的 ":"也有影响) 2.解锁用户, 3.授予新登 ...

随机推荐

  1. CORDIC原理与FPGA实现(2)

    CORDIC算法实现极坐标(polar)到直角坐标系(Cartesian)的变换. 1: function [horizonal,vertical]=polar2car(mag, pha); 2: x ...

  2. Openstack-Ceilometer-SNMP的使用

    1. 物理服务器配置 1.1安装 #yum install -y net-snmp net-snmp-utils 1.2      配置 复制[附件]中snmpd.conf文件到/etc/snmp/目 ...

  3. Verilog (二) multiplexer and decoder

    1  mutiplexer 数据选择器 1)  one-bit wide 2-1 mux wire dout = sel? din1 : din0; // conditional continuous ...

  4. 怎样在python中获取时间?

    from time import strftime date = strftime('%y%m%d') hour = strftime('%H%M%S')

  5. Mango Weekly Training Round #3 解题报告

    A. Codeforces 92A Chips 签到题.. #include <iostream> #include <cstdio> #include <cstring ...

  6. vector中pair的排序方法

    直接上代码: bool judge(const pair<int,char> a, const pair<int ,char> b) { return a.first<b ...

  7. scp: command not found如何解决

    今天给一台新的服务器,准备源码安装一些软件,需要使用scp复制文件时报错如下:-bash: scp: command not found 解决办法如下:安装scp的软件包:# yum install ...

  8. 啊D工具语句 适合Access和Mssql注入

    啊D注入工具中使用的SQL注入语句 爆user )) )= | ***** ?Id)) : ?Id : Id 检查SA权限:)))) 爆当前库: )) -- 检查是否为mssql数据库:and exi ...

  9. 时间与NSString转换

    //传进来时间字符串转换 + (NSString *) getChatTimeString:(NSString *)timeString { if (timeString==nil || timeSt ...

  10. javascript单元测试工具

    单元测试关注的是验证一个模块或一段代码的执行效果是否和设计或预期一样.有些开发人员认为,编写测试用例浪费时间而宁愿去编写新的模块.然而,在处理大型应用程序时,单元测试实际上会节省时间:它能帮助您跟踪问 ...