I have created a temporary table with dynamic columns. These columns are the values in a master table.
Say,
Id |Name
1 |Prepaid
2 |Postpaid
so the temporary table columns will be
Id Prepaid Postpaid
In this case the columns are dynamic.
consider the below code for temp table:
declare @temp as table (Id int, Prepaid float, postpaid float)
insert into @temp values(1,100,200)
insert into @temp values(1,10,500)
insert into @temp values(1,-100,-100)
insert into @temp values(1,10,200)
insert into @temp values(1,100,-100)
insert into @temp values(1,150,560)
insert into @temp values(1,90,200)
I need to insert a row with average of each column.
Average should be calculated taking the rows which meet the condition, i.e, the column should not contain a value -100.
I need to insert a row with average values like for the above values.
Id PrepaidAvg PostPaidAvg
1 76.6666666666667 320
Hard to determine exactly what result you expect, but here is one try:
If this is off you can get more elaborate: