当前位置: 移动技术网 > IT编程>开发语言>JavaScript > inner join 内联与left join 左联的实例代码

inner join 内联与left join 左联的实例代码

2017年12月12日  | 移动技术网IT编程  | 我要评论

卡拉峰,鼠标 单击变双击,兽兽最新照片

今天老板把我叫过去,给我分析了一下我写的存储过程【捂脸羞愧中。。。】,因为又临时加了个需求需要关联另外一个视图,我写成了内联,所以读取出来的数据少了好多。

select t1.motcarriername
   ,t2.routename
   ,y.buslicense
   ,y.acctprice
   ,y.price
   ,y.canacctprice
   ,y.centeracctprice
   ,y.otheracctprice
   ,y.staacctprice
   ,y.tkamount
   ,y.schbillid
   ,m.manualticketsstationfee
   ,m.manualticketsfee
  from
  (select b.motcarrierid
   ,b.routeid
   ,b.buslicense
   ,a.schbillid
   ,a.acctprice
   ,a.canacctprice
   ,a.centeracctprice
   ,a.otheracctprice
   ,a.price
   ,a.staacctprice
   ,a.tkamount
   from history.tkschbillhistory a
   ,history.tkserialschhistory b
   ,history.tkcarrystaschhistory c
   where a.drvdate between @pstartdate and @penddate 
    and a.schbillstatusid=1 
    and b.schid=a.schid 
    and b.drvdate=a.drvdate 
    and a.schid=c.schid 
    and a.drvdate=c.drvdate
  )y
  ,baseinfo.motorcarrier t1
  ,baseinfo.route t2
  ,settlement.dbo.view_manualticket m
  where t1.motcarrierid=y.motcarrierid and t2.routeid =y.routeid and m.buslicense=y.buslicense
  order by t1.motcarriername,t2.routename,y.buslicense

这种关联叫做内联,表a,表b where a.id=b.id,只有表a,表b里都有这个id,这条数据才会被显示出来。但是我的项目中需要的是以表a为主表,只要表a中有的数据都要显示出来,表b中有与表a相关的数据就显示,没有则置为空。

即a left join b on a.id=b.id

总结

以上所述是小编给大家介绍的inner join 内联与left join 左联的实例代码,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网