create table father(
       f_id number(2) primary key,
       f_name varchar2(10)
);
create table son(
       s_id number(2) primary key,
       s_name varchar2(10),
       s_height number(3,2),
       s_money number,
       f_id number(2),
       foreign key(f_id) references father(f_id)
);
--插入父亲信息
insert into father values(1,'何胜达');
insert into father values(2,'何忠达');
insert into father values(3,'何国达');
insert into father values(4,'陌生人');
--插入儿子信息
create sequence s1;
insert into son values(s1.nextval,'何亮',1.70,6000,1);
insert into son values(s1.nextval,'何星',1.68,4000,1);
insert into son values(s1.nextval,'何正安',1.73,7000,2);
insert into son values(s1.nextval,'何正明',1.72,4000,2);
insert into son values(s1.nextval,'何正元',1.68,8500,2);
insert into son values(s1.nextval,'何正陆',1.66,5000,3);
insert into son(s_id,f_id)values(s1.nextval,4);
--查询s_id、s_name、f_id
       select s_id,s_name,f_id from son;
--查询各儿子涨价20%以后的新学费,注意,8000块以下的不涨价。
       select s_name,s_money*1.2 from son where s_money>8000;
--查询s_id、s_name、f_id、f_name
       select f.*,s.s_id,s.s_name
       from father f
       join son s
       on f.f_id=s.f_id;
--查询f_id、f_name、儿子数(没有儿子的不显示)
       select f.f_id,f.f_name,count(s.s_name)as 有几个儿子
       from father f
       join son s
       on f.f_id=s.f_id
       group by f.f_id,f.f_name
       having count(s.s_name)>0;
--查询f_id、f_name、儿子数(没有儿子的个数显示为0)
       select f.f_id,f.f_name,count(s.s_name)as 有几个儿子
       from father f
       join son s
       on f.f_id=s.f_id
       group by f.f_id,f.f_name
       having count(s.s_name) is not null;
--找出不止有1个儿子的father信息:f_id、f_name、儿子数
       select f.f_id,f.f_name,count(s.s_name) as 不止一个儿子
       from father f
       join son s
       on f.f_id=s.f_id
       group by f.f_id,f.f_name
       having count(s.s_name)>1;
--找出儿子最多的father信息:fid、fname、儿子数
       select f.f_id,f.f_name,count(s.s_id) as 个数
       from father f
       join son s
       on f.f_id=s.f_id
       group by f.f_id,f.f_name;
--、找出fid为(7,9,11)的father中,各儿子的身高
     select s_name,s_height from son where f_id in(1,2,3);
--找出所有father中身高最高的儿子。
     select s_name from son where s_height=(
              select max(s_height) from son
       );
--找出各father中身高最高的儿子 
       select son.* from son,
              (select f_id,max(s_height) 最高儿子 from son group by f_id) x
        where son.f_id=x.f_id and son.s_height=x.最高儿子;
--找出身高在1.8到1.65之间的所有儿子及父亲信息:fid,fname,sid,sname,height;
--这里用到了where,之所以能用是因为前面没有用到聚合函数
      select f.*,s.s_id,s.s_name,s.s_height
      from father f
      join son s
      on f.f_id=s.f_id
      where s.s_height between 1.65 and 1.8;
select * from father;
select * from son;

<!DOCTYPE root [
 <!ELEMENT root (父亲+,儿子*)>
 <!ELEMENT 父亲 EMPTY>
 <!ELEMENT 儿子 EMPTY>
 <!ATTLIST 父亲
  fid CDATA #REQUIRED
  姓名 CDATA #REQUIRED
 >
 <!ATTLIST 儿子
  sid CDATA #REQUIRED
  姓名 CDATA #REQUIRED
  性别 (男|女) #REQUIRED
  年龄 CDATA #REQUIRED
  学费 CDATA #REQUIRED
  身高 CDATA #IMPLIED
  fid IDREFS #REQUIRED
 >
]>
<root>
 <父亲 fid="P_1" 姓名="何胜达"/>
 <父亲 fid="P_2" 姓名="何中达"/>
 <父亲 fid="P_3" 姓名="何国达"/>
 <父亲 fid="P_4" 姓名="陌生人"/>
 <儿子 sid="1" 姓名="何亮" 性别="男" 年龄="24" 学费="5000" 身高="1.72" fid="P_1"/>
 <儿子 sid="1" 姓名="何星" 性别="男" 年龄="24" 学费="5000" 身高="1.72" fid="P_1"/>
 <儿子 sid="1" 姓名="何正安" 性别="男" 年龄="24" 学费="1000" 身高="1.72" fid="P_2"/>
 <儿子 sid="1" 姓名="何明" 性别="男" 年龄="24" 学费="5000" 身高="1.72" fid="P_2"/>
 <儿子 sid="1" 姓名="何元" 性别="男" 年龄="24" 学费="5000" 身高="1.72" fid="P_2"/>
 <儿子 sid="1" 姓名="何陆" 性别="男" 年龄="24" 学费="5000" 身高="1.72" fid="P_3"/>
</root>

最新文章

  1. 反射——反射API,使用反射创建数组
  2. 网络流 HDU 3605
  3. 游标、动态sql、异常
  4. PacBio &amp; BioNano (Assembly and diploid architecture of an individual human genome via single-molecule technologies)
  5. ubuntu 安装compiz后 黑屏无法进入处理
  6. [Javascript] Gradient Fills on the HTML5 Canvas
  7. linux下安装软件的方法
  8. 网页WEB打印控件
  9. 基于Centos6.6的R720服务器四网口端口聚合的实践
  10. jsoup爬取图片到本地
  11. 应用负载均衡之LVS(二):VS_TUN和VS_DR的arp问题
  12. 【转载】Spark学习——spark中的几个概念的理解及参数配置
  13. H5 video播放视频遇到的问题
  14. Linux 给文件夹或者文件增加权限
  15. Java知多少(23)类的基本运行顺序
  16. oracle表复制
  17. LeetCode关于数组中求和的题型
  18. C#简单窗体应用程序(一)
  19. Java时间格式转换工具类
  20. 使用jxl 解析Excel

热门文章

  1. loadrunner11遇到的问题汇总及相应的解决方案(持续更新)
  2. CGContextRef 绘图
  3. 前端开发框架Bootstrap和KnockoutJS
  4. MySQL 批量插入 Update时Replace
  5. Android IOS WebRTC 音视频开发总结(六七)-- 在线教育虽火要做好其实不容易
  6. WAMP(Windows、Apache、MySQL、php)安装配置过程常见问题
  7. logging日志模块
  8. ffmpeg去logo&lt;转&gt;
  9. Python 前端之JS
  10. AX2009按照批次生产日期预留