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..
HDRG
0
Newbie Poster
Recommended Answers
Jump to PostYou 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`
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.