社區新手,對該主題的經驗有限。我試圖創建一個能夠逐行獲取指標總和的列。所以這個專欄將總計每個指標,給我第一個顧客總共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
社區新手,對該主題的經驗有限。我試圖創建一個能夠逐行獲取指標總和的列。所以這個專欄將總計每個指標,給我第一個顧客總共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
您可以使用
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
你的意思是這樣的:
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
完美,這爲我工作。非常感謝! – Riles