The basic idea is I have 3 separate SELECT statements that output a number. I need a percentage from those numbers. So the problem would look like this:
(a.count_one + b.count_two) -
(b.count_two + c.count_three) / (a.count_one + b.Count_two) * 100
When I do the code found below I only get the output of the first (a.count_one + b.count_two)
. BUT if I comment out the third portion which is / (a.count_one + b.count_two)
I successfully get the correct solution from (a.count_one + b.count_two) – (b.count_two + c.count_three)
.
So it appears, doing math of two statements is great, but when I throw in a third statement it pukes and only wants to show the solution of the first problem (a.count_one + b.count_two)
, but does not even try to calculate the solution for (a.count_one + b.count_two) – (b.count_two + c.count_three)
anymore. I'm a bit stumped why.
Select
(a.Count_one + b.Count_two) -
(b.Count_two + c.Count_three) / (a.Count_one + b.Count_two) * 100
as 'Final_Percentage'
from
(
select COUNT(v_Summary.ResourceID) AS Count_one
From [DB1].[dbo].[v_Summary]
) a,
(
select count([CN]) as Count_two
From [DB2].[dbo].[Computers]
WHERE cn NOT IN (SELECT name0 FROM [DB1].[dbo].[v_system] where v_system.Client0 = '1')
) b,
(
select COUNT(v_Summary.ResourceID) AS Count_three
From [DB1].[dbo].[v_Summary]
Where Description like '%/Fail'
) c
And to give additional information. The math problem with numbers:
(54558 + 373) – (373 + 117) / (54558 + 373) * 100
Or further solved:
(54931) - (490) / 55304 * 100 = 98.44%