My table contains votes of users for different items. It has the following columns:
id, user_id, item_id, vote, utc_time
Only id is a unique field and the combination of user_id and utc_time is probably also unique. But user can cast votes for any item many times.
A vote is not a number but rather has one of several possible values (e.g., "awful", "bad", "good", "excellent").
I need to count how many different users cast their last vote for a given #item# as "excellent", as "good", etc. So assuming I have only four different possible vote values, I need to get four records with the following fields:
vote, count_of_users
I understand how to count all votes, not only last votes of users:
SELECT vote, COUNT(id) FROM votes WHERE item_id=#item# GROUP BY vote;
But I cannot figure out how to count only the votes where utc_time = MAX(utc_time) for each user... Thanks for your help.
This question is connected to the previous question of mine: Select one row with MAX(column) for known other several columns without subquery