I have a table in mysql like this:

I want to aggregation by 5mins, so i create a procedure like this:

But, if the student_score changes(such as add another field), the procedure need to be updated.
If the student_score table has hundreds of fields, hundreds of assignment need to be writen in the procedure like “avg(src.score) as score”
My question is: is there a way make the procedure self-adaptive for the source table.
Your mention of “procedure” suggests some kind of stored procedure on the database server, but I take it that you’re simply referring to a piece of application code or the SQL queries it creates, right?
How to aggregate in 5 min intervals
Average of data for every 5 minutes in the given times also discusses averaging. As I wrote in my answer there, I’d accomplish this using
How to handle multiple score columns
About having to duplicate the
avgexpression for every column, I see three solutions.One would be not to create a separate table at all, but instead simply do the averaging in every query where you actually access these averages. If those queries use only a subset of all columns, then you would only have to name and average those.
The second solution would be generating the insertion query programatically. I.e. in the application from which you send these queries, have a piece of code query the db about the columns in the table, and construct the query to match. You could use this both for a real table (i.e. an insert statement) or a view (i.e. a create view statement).
Thirdly, if your scores all have similar meaning, you might be better off normalizing your table in such a way that these multiple columns are turned into multiple rows, with columns name, time, kind and score, where the kind column would be some (possibly enum) value used to distinguish the different kinds of scores.