27,580
社区成员
发帖
与我相关
我的任务
分享
select case when jvolum.jiayoujiaci is null then j.jjiayou else j.jjiayou - jvolum.jiayoujiaci*2 end as '加油架次',
j.jyue as '月份', j.jgongjin as '加油量(吨)' from (select
datepart(mm,BSTDK) as jyue,
count(BSTKD) as jjiayou,
sum(KWMENG)/1000 as jgongjin
from
jiayoudan
where datepart(YYYY,BSTDK) = @year
group by datepart(mm,BSTDK)) AS j
left join (select
datepart(mm,BSTDK) as yue,
count(BSTKD) as jiayoujiaci
from jiayoudan
where VOLUM = 0 and datepart(YYYY,BSTDK) = @year
group by datepart(mm,BSTDK)) AS jvolum on j.jyue = jvolum.yue
order by '月份'