社区新手,对该主题的经验有限。我试图创建一个逐行获取指标总和的列。因此,该列将总计每个指标,第一个客户总共给出3个,第二个给出2个。使用Microsoft Sql Server Mgmt Studio。任何帮助将不胜感激!
Customer Date Ind1 Ind2 Ind3 Ind4
12345 1-1-15 1 0 1 1
12346 1-2-15 0 1 1 0
答案 0 :(得分:2)
选择客户,日期,Ind1 + Ind2 + Ind3 + Ind4作为指标
答案 1 :(得分:2)
您可以使用
SELECT Customer
, Date
, Ind1
, Ind2
, Ind3
, Ind4
, Ind1+Ind2+Ind3+Ind4 As Indicators
FROM TABLE_NAME
将TABLE_NAME
替换为表格的名称。如果您不希望报告所有Ind1,Ind2,Ind3,Ind4
列,请使用
SELECT Customer
, Date
, Ind1+Ind2+Ind3+Ind4 As Indicators
FROM TABLE_NAME
答案 2 :(得分:2)
select customer,date, ind1+ind2+ind3 as Indicators from table_name order by Indicators
注意:您的列可能有null
个值,因此请使用:
select customer,date, isnull(ind1,0)+isnull(ind2,0)+isnull(ind3,0) as Indicators
from table_name order by Indicators