Reputation: 1712
I have two tables
A -- > id , name
B -- > id , value
In B table, I have multiple duplicate id, I want to find average of particular id and print id , name , AVG(value)
Here is my query for finding average in table B
SELECT id, AVG(value) FROM B GROUP BY id;
I need to perform JOIN operation, How to perform JOIN Operation with GROUP BY.
Upvotes: 0
Views: 1576
Reputation: 24395
Here's what you want: you want to group by both the id
and the name
SELECT a.id, a.name, avg(b.value)
FROM A
JOIN B ON A.id = B.id
GROUP BY A.id, A.name
Upvotes: 1