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

  • SEARCH
  • Home
  • 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 8881053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:16:16+00:00 2026-06-14T20:16:16+00:00

Here’s my database: This query select all supplements: SELECT a.id, a.name, a.image, a.url_segment, COUNT(b.id)

  • 0

Here’s my database:

enter image description here

This query select all supplements:

SELECT a.id, a.name, a.image, a.url_segment, COUNT(b.id) AS reviews_count, ROUND(AVG(b.rating), 2) AS reviews_rating, (((SELECT COUNT(*) FROM reviews) * (SELECT AVG(rating) FROM reviews)) + (COUNT(b.id) * AVG(b.rating))) / ((SELECT COUNT(*) FROM reviews) + COUNT(b.id)) AS bayesian_rating
FROM (`supplements` AS a)
LEFT JOIN `reviews` AS b ON `b`.`supplements_id` = `a`.`id`
GROUP BY `a`.`id`
ORDER BY `bayesian_rating` DESC

And this, all supplements from one subcategory (in this case, with id = 1):

SELECT a.id, a.name, a.image, a.url_segment, COUNT(b.id) AS reviews_count, ROUND(AVG(b.rating), 2) AS reviews_rating, (SELECT text FROM reviews WHERE supplements_id = a.id ORDER BY id DESC LIMIT 1) AS reviews_latest_text, (((SELECT COUNT(*) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1)) * (SELECT AVG(rating) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1))) + (COUNT(b.id) * AVG(b.rating))) / ((SELECT COUNT(*) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1)) + COUNT(b.id)) AS bayesian_rating
FROM (`supplements` AS a)
LEFT JOIN `reviews` AS b ON `b`.`supplements_id` = `a`.`id`
WHERE `a`.`subcategories_id` =  '1'
GROUP BY `a`.`id`
ORDER BY `bayesian_rating` DESC

The bayesian rating of the same supplements should be different on each query, but on both it’s returning the same.

Here’s is the part where I calculate the bayesian rating on the first query:

(((SELECT COUNT(*) FROM reviews) * (SELECT AVG(rating) FROM reviews)) + (COUNT(b.id) * AVG(b.rating))) / ((SELECT COUNT(*) FROM reviews) + COUNT(b.id)) AS bayesian_rating

On the second:

(((SELECT COUNT(*) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1)) * (SELECT AVG(rating) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1))) + (COUNT(b.id) * AVG(b.rating))) / ((SELECT COUNT(*) FROM reviews LEFT JOIN supplements ON (supplements.id = reviews.supplements_id AND supplements.subcategories_id = 1)) + COUNT(b.id)) AS bayesian_rating

For some reason the join is not making any difference to the result.

  • 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-14T20:16:17+00:00Added an answer on June 14, 2026 at 8:16 pm

    Since reviews are children of supplements, joining to supplements won’t return anything different for reviews.

    I think it’s expected that the two queries return the same.

    Also, by mathematical definition of AVG, the term

    (SELECT COUNT(*) FROM reviews) * (SELECT AVG(rating) FROM reviews)
    

    is identical to

    (SELECT SUM(rating) FROM reviews)
    

    so you can simplify (and speed up) your query but substituting this in.

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

Sidebar

Related Questions

here is the code i execute... dc.rs = dc.st.executeQuery(select count(*) from Accounts where date_join
Here is the code in a function I'm trying to revise. This example works
Here's what I'm trying to accomplish with this program: a recursive method that checks
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here is what I want to do. Use this HTML line and have the
Here is my program to find all the subsets of given set. To solve
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here is the problem I'm trying to solve for my game. I have this

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.