如何做SUM与案例

时间:2017-08-07 05:27:58

标签: sql

当我使用以下查询时,结果显示为我想要的结果:

select (TARIF + TAMBAHAN - (case when (select NILAI from PROMOTRIP where KODETRIP = OD.KODETRIP and URUTAN = OD.URUTAN) is null then 0 else (select NILAI from PROMOTRIP where KODETRIP = OD.KODETRIP and URUTAN = OD.URUTAN) end)) from ORDERDETAIL OD where KODETRIP = 'TR201408060051' and TGLBATAL is null 

enter image description here

但是当我想添加它时,结果错误:

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试将第一个查询合并为嵌套查询,并在外部查询上使用SUM。像这样:

SELECT SUM(*) FROM (YOUR_FIRST_QUERY)

答案 1 :(得分:0)

这样做。

return view('errors.404', ['msg' => 'some message']);