油款费  修车费  折旧费  运费  招待费   差旅费  佣金   销售净利   油款费:select sum(vou.FamountFor) as 油款费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1114
修车费:select sum(vou.FamountFor) as 修车费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1115
折旧费:select sum(vou.FamountFor) as 折旧费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1116
运费:select sum(vou.FamountFor) as 运费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1117
招待费:select sum(vou.FamountFor) as 招待费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1119
差旅费:select sum(vou.FamountFor) as 差旅费  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1118
佣金:select sum(vou.FamountFor) as 佣金  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
where a.Fnumber like '%521.%' and a.Faccountid = 1120
销售净利:(销售毛利 - 工资 - 油款费 - 修车费 - 折旧费 - 运费 - 招待费 - 差旅费 - 佣金)不用SUM这个语句怎么写到一条 

解决方案 »

  1.   

    select sum(油款费) as 油款费,sum(修车费) as 修车费,...
    from
    (
    select case a.Faccountid when 1114 then sum(vou.FamountFor) as 油款费,case a.Faccountid when 1115' then sum(vou.FamountFor) as 修车费...  from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
    where a.Fnumber like '%521.%'
    )
    至于那个销售净利,没看懂。呵呵
      

  2.   

    select sum(a.Faccountid = 1114 then vou.FamountFor else 0 end) as 油款费,
    sum(a.Faccountid = 1115 then vou.FamountFor else 0 end) as 油款费2,
    sum(a.Faccountid = 1116 then vou.FamountFor else 0 end) as 油款费3,
    sum(a.Faccountid = 1117 then vou.FamountFor else 0 end) as 油款费4,
    sum(a.Faccountid = 1118 then vou.FamountFor else 0 end) as 油款费5,
    sum(a.Faccountid = 1119 then vou.FamountFor else 0 end) as 油款费6,
    sum(a.Faccountid = 1120 then vou.FamountFor else 0 end) as 油款费7from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
    where a.Fnumber like '%521.%' 懒得打字了,你把上面的中自己改吧
      

  3.   


    是要这样的吗?
    create table #a
    (
    b  int 
    ,c   int
    ,d int
    )
    insert into #a
    select  1,2,1114
    union
    select   11,3,1114
    union
    select   21,3,1115
    union
    select   211,3,1115
    union
    select   2111,3,1115select 
    sum(c)
    from
    #a
    where
    b like '%1%'
    group by d
    order by d
    drop table #a
      

  4.   

    select sum(case when a.Faccountid = 1114 then vou.FamountFor else 0 end) as 油款费,
    sum(case when a.Faccountid = 1115 then vou.FamountFor else 0 end) as 油款费2,
    sum(case when a.Faccountid = 1116 then vou.FamountFor else 0 end) as 油款费3,
    sum(case when a.Faccountid = 1117 then vou.FamountFor else 0 end) as 油款费4,
    sum(case when a.Faccountid = 1118 then vou.FamountFor else 0 end) as 油款费5,
    sum(case when a.Faccountid = 1119 then vou.FamountFor else 0 end) as 油款费6,
    sum(case when a.Faccountid = 1120 then vou.FamountFor else 0 end) as 油款费7from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid 
    where a.Fnumber like '%521.%' 
    sorry上面写错
      

  5.   

    select 人名,
    sum(case when a.Faccountid = 1114 then vou.FamountFor else 0 end) as '油款费',
    sum(case when a.Faccountid = 1115 then vou.FamountFor else 0 end) as '修车费',
    sum(case when a.Faccountid = 1116 then vou.FamountFor else 0 end) as '折旧费',
    sum(case when a.Faccountid = 1117 then vou.FamountFor else 0 end) as '运费',
    sum(case when a.Faccountid = 1118 then vou.FamountFor else 0 end) as '差旅费',
    sum(case when a.Faccountid = 1119 then vou.FamountFor else 0 end) as '招待费',
    sum(case when a.Faccountid = 1120 then vou.FamountFor else 0 end) as '佣金'
    from t_voucherentry as vou  inner join t_account as a on vou.Faccountid = a.Faccountid
    where a.Fnumber like '%521.%' 
    and a.Faccountid in(1114,1115,1116,1117,1118,1119,1120)
    group by 人名不行把库给我
      

  6.   

    还有个问题最后一列 。
    max((en.fentryselfb0158 - en.famount) - 油款费 - 修车费 - 折旧费 - 运费 - 差旅费 - 招待费 - 运费) as 净利那几个值怎么取?