I have the following MySQL view which has some computed column (Percentage = COL_C/COL_B*100):
I can get the needed output with the following query:
SELECT COL_A, SUM(COL_B) COL_B, SUM(COL_C) COL_C, SUM(C)/SUM(B) *100 As Total_Per FROM TestView GROUP BY COL_A
Is there anyway I can get the Total_Per value directly from the computed Percentage values that are stored in Percentage column of TestView without aggregation on the other columns i.e COL_B and COL_C
What you are looking for is a weighted average, so given only the two percentages in the last column, no you can’t calculate it - if I understand correctly what you are asking for. You need to somehow apply the weight to each of the percentages.
[quote=“bmbsa, post:1, topic:222803, full:true”]
Is there anyway I can get the Total_Per value directly from the computed Percentage values that are stored in Percentage column of TestView without aggregation on the other columns i.e COL_B and COL_C[/quote]
SUM(C)/SUM(B) *100 gives 0.7
how do you propose to compute that from 100% and 50% ??