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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:32:49+00:00 2026-05-30T15:32:49+00:00

I have a table that in one column saved grade of a course and

  • 0

I have a table that in one column saved grade of a course and in another column save the ratio of that course, then I want to calculate average of courses with ratio, I write these code but I faces with error, please help me

select SUM((grade * ratio) / SUM(ratio)) as averageOfCourses
from myTable
  • 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-30T15:32:51+00:00Added an answer on May 30, 2026 at 3:32 pm

    Your problem is probably misplaced parentheses.

    SELECT SUM(grade * ratio) / SUM(ratio) AS averageOfCourses
      FROM myTable
    

    If you truly want to do a SUM of the values divided by a SUM, then you have to work a good deal harder; you can’t do aggregates of aggregates directly.

    To do what you wrote, you’d have to rewrite it as:

    SELECT SUM((grade * ratio) / sum_ratio) AS averageOfCourses
      FROM (SELECT grade, ratio, SUM(ratio) AS sum_ratio
              FROM myTable
             GROUP BY grade, ratio) AS precalculation
    

    (The final AS is required by standard SQL, but doesn’t contribute anything to this query.)

    In this context, I’m not even sure it gives a different answer.

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

Sidebar

Related Questions

i have a table that have one column (AbsoluteUrl NVARCHAR(2048)) and i want to
I have a TABLE elements with one COLUMN number, type SMALLINT that contains numbers
I have one table that has sales records and another table that has additional
I have a table where in one column, I have saved all the html
System is: SQL Server 2008-R2 I have a table that one of its column
I have a table that has two datetime columns (one for start time and
I have a table that containts a set of columns one of it is
I Have a table in my databse that one of the columns named NumOfView
Screenshot mockup: http://tinypic.com/r/y2qex/5 Problem: I have a table that has 53 columns; one for
I have one datatable. In that table I have columns named [Total Day], [Present

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.