Why is this SQL SUM statement correct? -
In my schema, I have one table projects and one table task. Every project involves tasks, hours and Percentage is complete.
Example table:
Percentage of ProjectID TaskID hours Full 1 1 100 50 1 2 120 80
I am trying to get weighted for the project Percentage I am using the following SQL statement:
SELECT P.ProjectID, P.ProjectName, SUM (T.Hours) as hours, SUM (T.PercentComplete * T. Hours) / 100 AS Full Horse, SUM (T. Parent Campotete * T. Horse) / SUM (T. Horse) AS Percentage P Inor JOIN TAS AS COMPLETE PROJECTS A AS T On T Provided = P. ProvidenceWare (P.Project = 1)
My question is about this part of the statement:
SUM (T. Parent Collectte * T. Horse) / SUM (T. Horse) AS Percent Full
This gives me the correct weighted percentage for this project (66% in case of sample data above).
-
SUM (T.PercentComplete * T. Hours) / 100
is the total number of hours. -
SUM (T.Hours))
is the total number of hours. -
The ratio of these two amounts, i.e.:
(S.P.PercentComplete * T. Hours () / 100) / SUM (T. Horse)
The ratio of the whole hour (this should be between 0 and 1).
- Returns a percentage that is multiplied by 100. < / Ul>
I like to keep percent percent like this in the database and take them to the presentation level. If the database stores "full hours" and "total hours" then it will be very easy and it will be all cent percent To share In addition to the 100 additional factors in the calculation, the problem was confused.
Comments
Post a Comment