你可以只添加值獲得的總和:
SELECT (at_salesbill.`billedTotal`+at_salesbill.`billedTotalTax`) as grantTotal,
at_salesbill.`billedTotal` AS at_salesbill_billedTotal,
at_salesbill.`billedTotalTax` AS billedTotalTax,
from at_salesbill
where at_salesbill.`billGuid` = 44;
然後,你可以做一個把戲,以獲得總與值一起,假設你在該行中有一個獨特的id
:
SELECT at_salesbill.id,
sum(at_salesbill.`billedTotal`+at_salesbill.`billedTotalTax`) as grantTotal,
at_salesbill.`billedTotal` AS at_salesbill_billedTotal,
at_salesbill.`billedTotalTax` AS billedTotalTax,
from at_salesbill
where at_salesbill.`billGuid` = 44
group by at_salesbill.id with rollup;
在這裏,sum()
沒有什麼意思 - 因爲每個組中都有一行。但是,with rollup
將添加一個總列,其中id
爲NULL
。
SELECT (case when at_salesbill.id is NULL then 'total' else '' end),
sum(at_salesbill.`billedTotal`+at_salesbill.`billedTotalTax`) as grantTotal,
at_salesbill.`billedTotal` AS at_salesbill_billedTotal,
at_salesbill.`billedTotalTax` AS billedTotalTax,
from at_salesbill
where at_salesbill.`billGuid` = 44
group by at_salesbill.id with rollup;
謝謝...好訣竅:) – Firu