0
Say I have a table like this
ID -- Val1 --- Val2
1     4        5
1     7        2
1     5        9
2     9        8
2     1        2
3     9        8
3     9        5
3     7        4
3     5        7
4     7        3
5     7        9
5     4        4

How do I get the averages of Val1 and Val2 per unit ID and store it into a new table? Notice that the number of rows per ID is different.

Eg new table:
ID -- Av_Val1 -- Av_Val2
1      5          5
2      5          5

and so on..
2
Contributors
2
Replies
18
Views
4 Years
Discussion Span
Last Post by HDRG
0

You can use something like:

INSERT INTO `new_table` (`av_val1`, `av_val2`)
    SELECT AVG(`val1`) AS `av_val1`, AVG(`val2`) AS `av_val2`
    FROM `table` GROUP BY `id`
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.