Hey Guys,
I have the following code, which averages the scores in a select statement and works no problem.
SELECT AVG(score) as 'avg' FROM
(SELECT d_key_id, frequency, weighting,(frequency*weighting) as 'score'
FROM users_to_keywords
WHERE s_user_id=$user_id
AND d_key_id = $score_key
ORDER BY score DESC)a
However, as there are some duplicated d_key_id's, i get dupliacted averages so need to use some form of group by function, I've tried the following code, but it throws up a load of errors!
SELECT d_key_id, AVG(score) as 'avg' FROM
(SELECT d_key_id, frequency, weighting,(frequency*weighting) as 'score'
FROM users_to_keywords
WHERE s_user_id=$user_id
AND d_key_id = $score_key
ORDER BY score DESC)a
GROUP BY d_key_id
Any help would be greatly appreciated!