0

我有二十行,我正在使用sum()

SELECT Sum(totalcon) AS totalcon_sum,
   Sum(vat3)     AS vat3_sum,
   Sum(rupes)    AS rupes_sum,
   pordernon,
   po_date,
   b_no,
   vendortext
FROM   po,
   potable,
   branch_master,
   delivery_master
WHERE  mr_assetpo = 'NCE'
   AND Substr(po.pordernon, 6, 2) = branch_master.b_no
   AND po.pordernon = delivery_master.deliverypo_no
   AND po.transid = potable.transid
   AND Year(po_date) = '"+req2+"'
   AND status = 'normal'
GROUP  BY Year(po_date)  

我的问题是:

每当我在总和之间有空白行时,也会计算该行。我不想计算空行。

4

2 回答 2

0

使用 IFNULL 函数

Sum(IFNULL(totalcon,0))

您的查询应该是:-

SELECT Sum(IFNULL(totalcon)) AS totalcon_sum,
   Sum(IFNULL(vat3))     AS vat3_sum,
   Sum(IFNULL(rupes))    AS rupes_sum,
   pordernon,
   po_date,
   b_no,
   vendortext
FROM   po,
   potable,
   branch_master,
   delivery_master
WHERE  mr_assetpo = 'NCE'
   AND Substr(po.pordernon, 6, 2) = branch_master.b_no
   AND po.pordernon = delivery_master.deliverypo_no
   AND po.transid = potable.transid
   AND Year(po_date) = '"+req2+"'
   AND status = 'normal'
GROUP  BY Year(po_date)  
于 2013-07-01T11:44:03.840 回答
0

你可以添加这个

   WHERE totalcon != ''

或者如果它的 null 使用这个

   WHERE totalcon is not null
于 2013-07-01T11:40:38.543 回答