• 【学亮开讲】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
  • 相关阅读:
    POJ2186(有向图缩点)
    POJ3352(连通分量缩点)
    POJ1523(割点所确定的连用分量数目,tarjan算法原理理解)
    POJ3694(求割边)
    POJ3177(无向图变双连通图)
    POJ1144(割点入门题)
    maven(1)-linux环境下安装maven
    linux(10)-linux环境下jdk配置自定义环境变量/etc/profile.d以及卸载自带openjdk
    ant(1)-linux环境下安装ant
    apache(2)-linux环境下apache-httpd编译安装
  • 原文地址:https://www.cnblogs.com/niwotaxuexiba/p/9986286.html
Copyright © 2020-2023  润新知