MySQL Forums
Forum List  »  General

Re: Nested GroupBy or for each
Posted by: Andreas Schulze
Date: October 17, 2018 08:19AM

One extra question appeared yesterday...
What can I do, when I want to calculate the average result based on at least 3 but max 4 results? In addition I do not have a counting column like above.

Pseudo Code would look like this:
if(number of results is less than 3 within campaign)

then -1
else

if(number of results is bigger than 4 within campaign)
pick only first 4 results
end if

calculate average

end if



For example (almost similar table to the first question):

measurement_campaign, sensor, measurement_result
A, S1, 0.1
A, S1, 0.5
A, S1, 0.4
A, S1, 0.3
A, S1, 0.6
A, S2, 1.1
A, S2, 1.2
A, S2, 1.1
B, S1, 0.5
B, S1, 0.7
B, S1, 0.6
B, S2, 0.4
B, S2, 0.3
B, S2, 0.2
B, S2, 0.8
B, S2, 0.4



The background is, that if I use too much values the weighting of the first results gets less.

Options: ReplyQuote


Subject
Written By
Posted
October 14, 2018 02:36AM
Re: Nested GroupBy or for each
October 17, 2018 08:19AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.