我想在列上使用公式,我想要的是我在列中有一个值我想将它乘以(100/SumofColumnValues)
我成功了到现在为止是让伯爵使用SQL Server列值的公式并将其存储在新列
select
Count(*) as ResponseCount,
PropertyValue As Answer
from
table
where
Questionid = 42 and formid = 1
group by
propertyvalue
的总和这给像这样
ResponseCount Answers
34 One
100 Two
,然后使用CTE:
With Temp As (
select
PropertyValue As Answers,
Count(*) As ResponseCount
from
questionerdetail
where
Questionid = 42 and formid = 1
group by
PropertyValue
)
select Sum(ResponseCount) As Total
from Temp
我得到
Total
134
我需要的是
ReponseCount Answer ResponsePercentage
34 One 25.37 TheFormula will be 34*(100/134)- (134 is the total sum of responsecount)
100 Two 74.62 TheFormula Will be 100*(100/134)
MS Sql 2012对不起! –