The following query seems to have a problem to calculate “ratingValue” because there is SUM(h.liked) inside a SUM.
SELECT d.itemID1 as item,
sum(d.sum + d.count*SUM(h.liked))/sum(d.count) as ratingValue
FROM history h, dev d
WHERE h.userID=:id_user
AND d.itemID1<>h.itemID
AND d.itemID2=h.itemID
GROUP BY d.itemID1,h.itemID
For a better understanding this is the original and working query (from the Slop One algorithm) :
I just substitute the “rating” table with “history” because in my case r.ratingValue is the sum of all the “like” a user has given to an itemID (=> r.ratingValue = SELECT SUM(liked) FROM history GROUP BY h.itemID ) :
SELECT d.itemID1 as item,
sum(d.sum + d.count*r.ratingValue)/sum(d.count) as ratingValue
FROM rating r, dev d
WHERE r.userID=$userID
AND d.itemID1<>r.itemID
AND d.itemID2=r.itemID
GROUP BY d.itemID1
As the error message says, you cannot next aggregation functions. I think you mean:
That is, you need to do the aggregation separately, in this case using a subquery. I also fixed the join syntax in your query.