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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:54:16+00:00 2026-05-16T04:54:16+00:00

In my schema, I have a table Projects, and a table Tasks. Each project

  • 0

In my schema, I have a table Projects, and a table Tasks. Each project is comprised of tasks. Each task has Hours and PercentComplete.

Example table:

ProjectID    TaskID    Hours   PercentComplete
1            1         100     50
1            2         120     80

I am trying to get the weighted percentage complete for the project. I am doing this using the following SQL statement:

SELECT P.ProjectID, P.ProjectName, SUM(T.Hours) AS Hours, 
SUM(T.PercentComplete * T.Hours) / 100 AS CompleteHours, 
SUM(T.PercentComplete * T.Hours) / SUM(T.Hours) AS PercentComplete
FROM Projects AS P INNER JOIN
        Tasks AS T ON T.ProjectID = P.ProjectID
WHERE     (P.ProjectID = 1)

My question is about this part of that statement:

SUM(T.PercentComplete * T.Hours) / SUM(T.Hours) AS PercentComplete

This gives me the correct weighted percentage for this project (in the case of the sample data above, 66%). But I cannot seem to wrap my head around why it does this.

Why does this query work?

  • 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-16T04:54:16+00:00Added an answer on May 16, 2026 at 4:54 am
    • SUM(T.PercentComplete * T.Hours) / 100 is the number of complete hours.
    • SUM(T.Hours) is the total number of hours.
    • The ratio of these two amounts, i.e.:

      (SUM(T.PercentComplete * T.Hours) / 100) / SUM(T.Hours)
      

      is the proportion of hours complete (it should be between 0 and 1).

    • Multiplying this by 100 gives the percentage.

    I prefer to keep percentages like this out of the database and move them to the presentation layer. It would be much easier if the database stored “hours completed” and “hours total” and did not store the percentages at all. The extra factors of 100 in the calculations confuse the issue.

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

Sidebar

Related Questions

I have this schema: There is a table for persons. Each person has one
I have 3 tables: projects, skills and project_skills. In projects table i hold project's
I have a table which have schema like this id name 1 jack 2
In my SQL Server database schema I have a data table with a date
I have a table schema which is essentially a bunch of transaction info with
Say I have this table schema. ID AccNo Amount Say I have this data
I have no control over database schema and have the following (simplified) table structure:
I know that I should have schema of a table before calling NewRow method
Is it possible to have same table name on different schema with different data
I have a schema design that looks like this: Table: User Row Column Family

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.