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 6390731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:35:03+00:00 2026-05-25T03:35:03+00:00

having difficulties with a form and mysql. 3 tables, 1 sum of a tables

  • 0

having difficulties with a form and mysql. 3 tables, 1 sum of a tables values. The form provides the value to search, but it does not work with the “WHERE >= ‘$search_total_rating” being in the wrong place, i am doing something very wrong here.

        $result = mysql_query("SELECT coffeeshops.*, services.*, ratings.*, sum(temp.total) as          final_total FROM coffeeshops inner join services on coffeeshops.shop_id=services.shop_id
inner join ratings on coffeeshops.shop_id=ratings.shop_id
    inner join (select SUM(comfort + service + ambience + friendliness + spacious)/(5) / COUNT(shop_id) AS total, shop_id FROM ratings GROUP BY shop_id) as temp on coffeeshops.shop_id=temp.shop_id WHERE >= '$search_total_rating'");

I do not fully understand this, but what i am trying to do is WHERE the total rating sum is >= selected rating. I am trying to access final_total which is not an actual column in my database, that is why SUM is being used to get the total rating for each shop. Hopefully it is a minor shuffle of the code. Thanks

  • 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-05-25T03:35:03+00:00Added an answer on May 25, 2026 at 3:35 am

    You have already calculated your total in the subquery. No need for a second SUM().

    SELECT coffeeshops.*
         , services.*
         , ratings.*
         , temp.total as final_total 
    FROM coffeeshops
      inner join services
        on coffeeshops.shop_id = services.shop_id
      inner join ratings 
        on coffeeshops.shop_id = ratings.shop_id
      inner join
        ( select SUM(comfort + service + ambience + friendliness + spacious) / 5
                 / COUNT(shop_id) AS total
               , shop_id 
          FROM ratings 
          GROUP BY shop_id
        ) as temp 
        on coffeeshops.shop_id = temp.shop_id 
    WHERE temp.total >= '$search_total_rating'
    

    You could also use a HAVING in the subquery:

    SELECT coffeeshops.*
         , services.*
         , ratings.*
         , temp.total as final_total 
    FROM coffeeshops
      inner join services
        on coffeeshops.shop_id = services.shop_id
      inner join ratings 
        on coffeeshops.shop_id = ratings.shop_id
      inner join
        ( select SUM(comfort + service + ambience + friendliness + spacious) / 5
                 / COUNT(shop_id) AS total
               , shop_id 
          FROM ratings 
          GROUP BY shop_id
          HAVINGE total >= '$search_total_rating'
        ) as temp 
        on coffeeshops.shop_id = temp.shop_id 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having difficulties creating a query. I have googled a lot but did not
I'm having difficulties with multiple joins in the NHibernate Criteria search. Say I had
I am having some difficulties with a form that is part of a lightbox
I am having some difficulties in making a form submission via a boxcomponent. I
I am having difficulties testing Controllers in Codeigniter: I use Toast but when I
I'm having difficulties getting an association to work with simple_form . I have the
I'm having difficulties believing this question hasn't been asked before, but I couldn't find
I am having some difficulties getting results from a form via Perl. I believe
I'm having some difficulties with the php form concept which is as follows: There
I am having difficulties with a MYSQl select statement. Is it possible to return

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.