Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: corrected question please see Re: Why do these two sum SQLs give different results since they should be identical Very odd!!
The problem are possible NULL values in those two columns.
The result of the first Statement should be higher (if the figures are positive) as the sum on the column values is build independently from the value of the other column. Whenever one of the columns has a NULL value in Statement 2 the value of the other statement will be ignored as the result of a calculation "figure + null" is also null.
You should take care on null values in both statements!
Statement 1:
SELECT ( NVL(SUM(...),0) + NVL(SUM(...),0) ) / 2 ..
Statement 2:
SELECT ( SUM(NVL(...,0)) + SUM(NVL(...,0)) ) / 2 bye
Roger