Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8311333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:46:48+00:00 2026-06-08T19:46:48+00:00

The following query seems to have a problem to calculate ratingValue because there is

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:46:51+00:00Added an answer on June 8, 2026 at 7:46 pm

    As the error message says, you cannot next aggregation functions. I think you mean:

    SELECT d.itemID1 as item, 
           sum(d.sum + d.count*h.sumliked)/sum(d.count) as ratingValue
    FROM (select h.userId, h.itemId, sum(h.liked) as sumliked
          from history h
          group by h.userId, h.itemId
         ) h join
         dev d 
         on h.userID=:id_user AND
            d.itemID1<>h.itemID AND
           d.itemID2=h.itemID 
    GROUP BY d.itemID1
    

    That is, you need to do the aggregation separately, in this case using a subquery. I also fixed the join syntax in your query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following xpath query which seems to be working but I just
I have a problem where a bitwise operation on a query like the following
I have the following code: (query added) $weight_table = mysql_query (SELECT * FROM .$prefix.weight
I have the following query: SELECT dev.DeviceName, Count(dom.DomainID) AS CountOfDomains FROM tblDevices dev JOIN
I have the following tabular report using the following query: select id, name, telephone,
I am facing a problem. I have one query Select * from tabA where
I try to run the following raw query in android, it seems not work
The following query is taking more than 25 seconds to complete: SELECT c.* ,
The following query: select unnest(Table2.L) as X, unnest(Table1.O) from Table1, Table2 where Table1.code =
I am having the following problem: I have a WCF service that checks a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.