I'd like to get an average per type then join the aggregated table as a new column in the original table. Here's a visualization and code of what I'm attempting to do:
-- The original table --
ID | Cnt | Type
1 5 A
1 6 A
2 4 B
-- New Table --
ID | Cnt | Type | Avg
1 5 A 5.5
1 6 A 5.5
2 4 B 4.0
The code I have written thus far is the following:
select AVG(Cnt)
from old
group by(type)
right join on old
But, obviously it's not correct since a syntax error is raised. What would be the fix for this? I apologize in advance if my question is similar to an already existing one.