zoukankan      html  css  js  c++  java
  • 【学亮开讲】Oracle内外连接查询20181119

    --内连接查询
    --需求:查询显示业主编号、业主名称、业主类型名称
    select
    os.id 业主编号,os.name 业主名称,ot.name 业主类型名称
    from t_owners os,t_ownertype ot
    where os.ownertypeid=ot.id
    --需求:查询显示业主编号、业主名称、地址和业主类型
    select ow.id 业主编号,ow.name 业主名称,ad.name 地址,ot.name 业主类型
    from t_owners ow,t_ownertype ot,t_address ad
    where ow.addressid = ad.id and ow.ownertypeid = ot.id
    --需求:查询显示业主编号、业主名称、地址、所属区域、业主分类
    select ow.id 业主编号,ow.name 业主名称,ad.name 地址,ar.name 所属区域,ot.name 业主类型
    from t_owners ow,t_ownertype ot,t_address ad,t_area ar
    where ow.addressid = ad.id and ow.ownertypeid = ot.id and ad.areaid = ar.id
    --需求:查询显示业主编号、业主名称、地址、所属区域、收费员、业主类型
    select ow.id 业主编号,ow.name 业主名称,ad.name 地址,ar.name 所属区域,op.name 收费员,ot.name 业主类型
    from t_owners ow,t_ownertype ot,t_address ad,t_area ar,t_operator op
    where ow.addressid = ad.id and ow.ownertypeid = ot.id and ad.areaid = ar.id and ad.operatorid = op.id
    
    --外连接查询
    --需求:查询业主的账务记录,显示业主编号、名称、年、月、金额。如果此业主没有账务记录也要列出姓名
    --sql1999写法
    select ow.id 业主编号,ow.name 业主名称,ac.year 年,ac.month 月,ac.money 金额
    from t_owners ow left join t_account ac
    on ac.owneruuid = ow.id 
    --Oracle写法
    select ow.id 业主编号,ow.name 业主名称,ac.year 年,ac.month 月,ac.money 金额
    from t_owners ow,t_account ac
    where ow.id=ac.owneruuid(+)
    --右外连接查询
    --需求:查询业主的账务记录,显示业主编号、名称、年、月、金额。如果账务记录没有对应的业主信息,也要列出记录。
    --sql1999写法
    select ow.id 业主编号,ow.name 业主名称,ac.year 年,ac.month 月,ac.money 金额
    from t_owners ow right join t_account ac
    on ac.owneruuid = ow.id
    --Oracle写法
    select ow.id 业主编号,ow.name 业主名称,ac.year 年,ac.month 月,ac.money 金额
    from t_owners ow,t_account ac
    where ow.id(+)=ac.owneruuid
  • 相关阅读:
    正则表达式简介
    PHP中简单的页面缓冲技术
    PHP 程序加速探索
    PHP中通过Web执行C/C++应用程序
    PHP实现聊天室的主动更新与被动更新
    php中Cookie及其使用
    Linux 下 PHP 连接 MS SQLServer 的办法
    网站加速 PHP 缓冲的免费实现方法
    Spark Streaming中的基本操作函数实例
    Scala中的s函数
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9986286.html
Copyright © 2011-2022 走看看