如何在一个表中获得组合列的总和

如何在一个表中获得组合列的总和

问题描述:

我想获得表格中的一些数据。



这是我的查询



I want to get SUM of some data in my table.

This is my query

Select paidCustomerCode,count(tblComparePods.hAWBNum) As hAWBNum,Sum(weight) As weight,SUM(Value) from tblOutboundHeader INNER JOIN tblComparePods ON tblOutboundHeader.hAWBNum=tblComparePods.hAWBNum  WHERE (Date>='2013/11/15' AND Date<='2013/11/30') AND tblComparePods.isconfirm ='0'Group by paidCustomerCode 


I Want to add this flowing query for this Function SUM(Value)  

CASE WHEN [ChageValue] = 0 THEN [Value] ELSE [ChageValue] END AS [Value](combine two columns in one table)





任何人都可以帮助我?



Any one can help me??

尝试用SUM替换SUM(Value)(COALESCE(nullif(ChageValue,0),value))



Try replacing SUM(Value) with SUM(COALESCE(nullif(ChageValue,0),value))

Select paidCustomerCode,count(tblComparePods.hAWBNum) As hAWBNum,Sum(weight) As weight,SUM(COALESCE(nullif(ChageValue,0),value)) from tblOutboundHeader INNER JOIN tblComparePods ON tblOutboundHeader.hAWBNum=tblComparePods.hAWBNum  WHERE (Date>='2013/11/15' AND Date<='2013/11/30') AND tblComparePods.isconfirm ='0' AND paidCustomerCode= '0001' Group by paidCustomerCode 





注意:我没有测试过只是检查语法错误的示例数据。 NULLIF仅在2005年开始提供。



Note: I have not tested with sample data just checked for syntax errors. NULLIF is available only from 2005 onwards.