computed column with aggregate function
I have seven columns in my table: hours, weight, status, total_hours, total_weight a开发者_StackOverflow中文版nd percentage
total_weight = weight where status = 'X' total_hours = hours where status = 'X' percentage = total_hours/sum(weight)
sum(weight) is an aggregate function
I would like to specify formula to generate the three computed columns. What do i do?
From what you're saying, you want 3 columns to be aggregations of data across the entire table? SQL Server won't allow this because aggregate functions cannot be used in computed columns. Now you could possibly have user defined scalar functions return the values in the columns, but this would not be able to be persisted and I see little value in such a case.
精彩评论