Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find Percentage between 2 table values

Author  Topic 

netwerkassist
Starting Member

13 Posts

Posted - 2012-01-05 : 22:03:38
I have a query that I need help with to return me the percentages of job timings from two temp tables

SELECT A.Average-B.Average /A.Average *100 AS PERCENTAGE_IMPROVEMENT,A.noofexec as newExecutioncount,B.noofexec as oldexecutioncount
FROM
(
SELECT PRCSNAME, avg(jobtime)AS Average, max(jobtime)AS Maximum, min(jobtime)AS Minimum ,COUNT(1) AS noofexec FROM #JobTimings_NEWSERV group by PRCSNAME
) A

JOIN
(
SELECT PRCSNAME, avg(jobtime)AS Average, max(jobtime)AS Maximum, min(jobtime)AS Minimum,COUNT(1) AS noofexec FROM #JobTimings_OLDSERV group by PRCSNAME
) B
ON A.PRCSNAME=B.PRCSNAME
ORDER BY 2

But not return the correct percntages, they are way too high.

Appreciate help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-01-05 : 23:34:25
[code]
SELECT (A.Average - B.Average) / A.Average * 100 AS PERCENTAGE_IMPROVEMENT,
A.noofexec as newExecutioncount,
B.noofexec as oldexecutioncount
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-06 : 14:19:42
i hope Average is of type float else make it like

(A.Average - B.Average) / A.Average * 100.0

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -