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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:45:16+00:00 2026-06-15T16:45:16+00:00

I have one problem with this query; I can’t seem to get ((total +

  • 0

I have one problem with this query; I can’t seem to get ((total + rec_host) / 2) AS total2 to work. How would I go about this procedure without doing:

((((rank_ur + rank_scs + rank_tsk + rank_csb + rank_vfm + rank_orr) / 6) + rec_host ) / 2)

Here’s my Query:

   SELECT host_name, 
       SUM(rank_ur) AS cnt1, 
       SUM(rank_scs) AS cnt2,
       SUM(rank_tsk) AS cnt3,
       SUM(rank_csb) AS cnt4,
       SUM(rank_vfm) AS cnt5,
       SUM(rank_orr) AS cnt6,
       SUM(IF(rec_host = 1,1,0)) AS rh1,
       SUM(IF(rec_host = 0,1,0)) AS rh2,
       ((rank_ur + rank_scs + rank_tsk + rank_csb + rank_vfm + rank_orr) / 6) AS total,
       ((total + rec_host) / 2) AS total2
   FROM lhr_reviews 
   GROUP BY host_name
   ORDER BY total 
   DESC LIMIT 0,10
  • 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-15T16:45:18+00:00Added an answer on June 15, 2026 at 4:45 pm

    What you could do is this:

    select x.*, ((x.total + rec_host) / 2) AS total2
    from (
    
    SELECT host_name, rec_host,
           SUM(rank_ur) AS cnt1, 
           SUM(rank_scs) AS cnt2,
           SUM(rank_tsk) AS cnt3,
           SUM(rank_csb) AS cnt4,
           SUM(rank_vfm) AS cnt5,
           SUM(rank_orr) AS cnt6,
           SUM(IF(rec_host = 1,1,0)) AS rh1,
           SUM(IF(rec_host = 0,1,0)) AS rh2,
           ((rank_ur + rank_scs + rank_tsk + rank_csb + rank_vfm + rank_orr) / 6) AS total
       FROM lhr_reviews 
       GROUP BY host_name
       ORDER BY total 
       DESC LIMIT 0,10
    ) as x
    ;
    

    You cannot use the column as an alias when the alias and other column are in the same level of SELECT. So you can use a derived query which lets you basically rename your columns and/or name any computed columns.Check on Rubens Farias and Rob Van Dam answer here

    PS: will search for a better article to update the answer 🙂

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

Sidebar

Related Questions

This is a thought problem, and one I have been wrestling with for about
This is my problem, I have one textbox, one button and one label. Everything
I really have problem with this one. So I have a jar with a
My problem is this one, I am using Sharepoint 2010, I have a form
So i'm having this problem. I have two tables (Oracle), one is called Destination
I have a problem with my WCF Data Service, and this one is just
I have one problem that I can't resolve. I have 2 tables. Table 1:
I have a memory problem that I can't figure out. I have one class
I have a problem with mysql query. I am writing SQL query to get
i have a problem. I'm running following query. I have only one record in

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.