How to create a MySQL stored aggregate function?
I need to write a stored function that does an aggregate operation on a column. Let's say a median (but actually, there are many different summary functions I want to implement). Ideally, I would like to have something like medBy( col1 col2 col3 ) which then for each row returns a median of the col1 values of all the rows that have the same col2 and col3 value as this one. That way, I wouldn't have to do GROUP BY on the whole query, just have a repeating value in that one column. This question ( How to write the quantile aggregate function? ) asked something similar, but it got answered with a