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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:03:17+00:00 2026-06-02T15:03:17+00:00

I have the following code below and I’m trying to get an AVG for

  • 0

I have the following code below and I’m trying to get an AVG for the 3 columns.

 SELECT 
    (SUM(score) * .3) As score_a,
    (SUM(score) * .6) As score_b,
    (SUM(score) * .8) As score_c

     --now I want to get the AVG of the above scores
    AVG(score_a + score_b + score_c) As avg_score
 FROM score_table

but this does not work. The error I’m getting is “Invalid column name score_a”.
I’m using SQL Server 2008

  • 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-02T15:03:17+00:00Added an answer on June 2, 2026 at 3:03 pm

    AVG() is an aggregate function that takes values from multiple rows and gives their average.

    You’re trying to average 3 columns.

    I your specific case, it can be done using algebra.

    SELECT 
      (SUM(score) * .3)                       As score_a,
      (SUM(score) * .6)                       As score_b,
      (SUM(score) * .8)                       As score_c,
      (SUM(score) * ((0.3 + 0.6 + .8) / 3.0)) As score_avg
    FROM
      score_table
    

    In a more generalised case, you’re limited by the fact that you can’t reference a column you just defined in another column…

    SELECT
      a + 1      AS inc_a,
      inc_a * 2  AS this_is_invalid
    FROM
      your_table
    

    You’d either need to repeat yourself, or use a sub query…

    Repetition

    SELECT 
      (SUM(score) * .3)                                                 As score_a,
      (SUM(score) * .6)                                                 As score_b,
      (SUM(score) * .8)                                                 As score_c,
      ((SUM(score) * .3) + (SUM(score) * .3) + (SUM(score) * .3)) / 3.0 As score_avg
    FROM
      score_table
    

    Sub Query

    SELECT
      score_a,
      score_b,
      score_c,
      (score_a + score_b + score_c) / 3.0 AS score_avg
    FROM
    (
      SELECT 
        (SUM(score) * .3)                                               As score_a,
        (SUM(score) * .6)                                               As score_b,
        (SUM(score) * .8)                                               As score_c
      FROM
        score_table
    )
      AS data
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have the following code below, where i try to get all the
Hi people I have the following code (shown below) and I am trying to
i have the following code below: const char* timeformat = %Y-%m-%d %H:%M:%S; const int
I want to know is below code correct ? I have following code which
I have the following C# code below. Object first = 5; Object second =
i have the following code: <h3> Your Profile </h3> The information below is what
i have the following code below but sometime the serving_description tag isn't there. Right
I have the following code below: BEGIN TRY BEGIN TRANSACTION -- DO SOMETHIING COMMIT
See i have this following code below, at line no.9 i'm calculating some dates
I have the following *code below, every time I refresh the page it asks

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.