本文介绍了如何在一个表中获得组合列的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得表格中的一些数据。
这是我的查询
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??
推荐答案
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.
这篇关于如何在一个表中获得组合列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!