I am attempting to write a code that will take the amounts for four weeks and average them out. Right now, if there are any zero values within any week, the average results comes up NULL. I have used Coalesce to replace the NULL values within the given weeks to 0, I don't know if this is affecting the averaging. Here is the code:
(SUM(A.NET_PAY) + SUM(B.NET_PAY) + SUM(C.NET_PAY) + SUM(D.NET_PAY)) /
(COUNT(COALESCE(A.NET_PAY,0)) + COUNT(COALESCE(B.NET_PAY,0)) + COUNT(COALESCE(C.NET_PAY,0)) +
COUNT(COALESCE(D.NET_PAY,0))) AS AVERAGE
Any help is much appreciated. Thanks
(SUM(A.NET_PAY) + SUM(B.NET_PAY) + SUM(C.NET_PAY) + SUM(D.NET_PAY)) /
(COUNT(COALESCE(A.NET_PAY,0)) + COUNT(COALESCE(B.NET_PAY,0)) + COUNT(COALESCE(C.NET_PAY,0)) +
COUNT(COALESCE(D.NET_PAY,0))) AS AVERAGE
Any help is much appreciated. Thanks