Calculate the total percentage from already computed percentages

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

Thanks

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.

1 Like

[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% ??

i suggest you just go with what you have :slight_smile:

Thanks guys.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.