怎么把下面代码里的dnwbsc和dnxmft所代表的值相加合并成一个ljwbsr as ( select case when a.sgdw = 'SD1055' and sgxmb = 'SD1034' then 'SD103401' else nvl(a.sgxmb,a.sgdw) end sgdw, sum(case when yftdw is null or ( sgdw= 'SD1056' and c.office_type = 3) then ysje else 0 end) dnwbsc, sum(case when yftdw is null or ( sgdw= 'SD1056' and c.office_type = 3) then 0 else ysje end) dnxmft from a_sgxx_Srxx1 a left join mv_shigongxinxi b on a.logtripinfoid = b.id left join js_sys_office c on a.yftdw = c.office_code where a.status = 1 and a.jslx = 'WBSR' AND b.complete = 0 AND b.unfinishedreason = '无' and substr(a.bbyf,1,6)<=#{bbyf} and substr(a.bbyf,1,4) = substr(#{bbyf},1,4) <if test="wgrq1!=null and wgrq1!=''"> and (to_char(b.arrivehometime,'yyyy-MM-dd hh24:mi:ss')>=#{wgrq1} <if test="jznd!=null and jznd!=''"> or a.jznd = #{jznd} </if>) </if> <if test="wgrq2!=null and wgrq2!=''"> and to_char(b.arrivehometime,'yyyy-MM-dd hh24:mi:ss')<=#{wgrq2} </if> group by case when a.sgdw = 'SD1055' and sgxmb = 'SD1034' then 'SD103401' else nvl(a.sgxmb,a.sgdw) end ),
时间: 2023-11-27 14:54:09 浏览: 63
你可以使用以下代码来实现将dnwbsc和dnxmft相加合并为一个字段ljwbsr:
```
ljwbsr as (
select
case
when a.sgdw = 'SD1055' and sgxmb = 'SD1034' then 'SD103401'
else nvl(a.sgxmb,a.sgdw)
end sgdw,
sum(
case
when yftdw is null or (sgdw= 'SD1056' and c.office_type = 3)
then ysje
else 0
end
) + sum(
case
when yftdw is not null and (sgdw <> 'SD1056' or c.office_type <> 3)
then ysje
else 0
end
) as ljwbsr
from a_sgxx_Srxx1 a
left join mv_shigongxinxi b on a.logtripinfoid = b.id
left join js_sys_office c on a.yftdw = c.office_code
where a.status = 1
and a.jslx = 'WBSR'
and b.complete = 0
and b.unfinishedreason = '无'
and substr(a.bbyf,1,6) <= #{bbyf}
and substr(a.bbyf,1,4) = substr(#{bbyf},1,4)
<if test="wgrq1!=null and wgrq1!=''">
and (
to_char(b.arrivehometime,'yyyy-MM-dd hh24:mi:ss') >= #{wgrq1}
<if test="jznd!=null and jznd!=''">
or a.jznd = #{jznd}
</if>
)
</if>
<if test="wgrq2!=null and wgrq2!=''">
and to_char(b.arrivehometime,'yyyy-MM-dd hh24:mi:ss') <= #{wgrq2}
</if>
group by
case
when a.sgdw = 'SD1055' and sgxmb = 'SD1034' then 'SD103401'
else nvl(a.sgxmb,a.sgdw)
end
)
```
在这个修改后的代码中,我们使用了两个 sum 函数将dnwbsc和dnxmft相加,并将它们合并成了一个字段ljwbsr。同时,我们也修改了第一个sum函数的条件,使其仅计算dnwbsc的值,而新的sum函数仅计算dnxmft的值。最后,我们将这个新的字段添加到了select语句和group by语句中。
阅读全文