select e.Fname as 业务员,en.fentryselfb0158 as 销售收入
from icstockbillentry as en inner join icstockbill as b on en.Finterid = b.Finterid
left join t_emp as e on e.Fitemid = b.Fempidselect e.Fname  as 业务员,convert(money,(case when a.Faccountid = 1114 then vou.FamountFor else 0 end)) as '油款费',
from t_voucherentry as vou inner join t_account as a on a.Faccountid = vou.Faccountid
left join t_itemdetail as it on it.Fdetailid = vou.Fdetailid
left join t_emp as e on e.Fitemid = it.F3 2条语句 想拼成一个。但是不管用 inner 还是left 还是 right (join)数据就都关联上了。
想要的结果是销售收入和业务员关联,
油款费和业务员关联。
但是合成一个表的时候不想让销售收入、油款费一起关联业务员显示。高手帮帮!!急

解决方案 »

  1.   

    select A.业务员,销售收入 ,油款费  from 
    (
    select e.Fname as 业务员,en.fentryselfb0158 as 销售收入 
    from icstockbillentry as en inner join icstockbill as b on en.Finterid = b.Finterid 
    left join t_emp as e on e.Fitemid = b.Fempid
    )   Ainner join
    (
    select e.Fname  as 业务员,convert(money,(case when a.Faccountid = 1114 then vou.FamountFor else 0 end)) as '油款费', 
    from t_voucherentry as vou inner join t_account as a on a.Faccountid = vou.Faccountid 
    left join t_itemdetail as it on it.Fdetailid = vou.Fdetailid 
    left join t_emp as e on e.Fitemid = it.F3 
    )   B
    on A.业务员=B.业务员
     
      

  2.   

    但是个人感觉你这样不合适,
    你应该以业务员的基本信息为主表  分别连接 销售收入表和油款表类似这样select 业务员名字,销售收入,油款费 from 业务员基本信息表 
    left outer join 销售收入表  on 业务员基本信息表.业务员编号=销售收入表.业务员编号
    left outer join 油款费      on 业务员基本信息表.业务员编号=油款费    .业务员编号
      

  3.   

    楼主,这样提问题没人能给你解决,
    转帖到sql版,把表关系都写清楚才行