I have a surprisingly basic question; I thought the answer was going to be more straightforward regarding Averaging columns. Here is my table with sample values:
Table: ratings
id, rating, item_id
Sample data
1, 5, 3
2, 1, 2
3, 2, 3
4, 4, 4
5, 1, 2
What if I want to get the average rating of the item_id's marked "3"
The real answer would be 2.5 since there is a 3 with a1, and another with a 5.
Here is the query I believe:
SELECT avg(rating) as average FROM ratings;
How do I specify ONLY the ratings with an item_id of 3? Do I use WHERE? GROUP BY? something else?
And the second part of the question: How do I output this into a single variable?