Average Function Issue

Database

Average Function Issue

Why does the Average Function behave differently when used in an Analytical Functions?

Example

SELECT CAST(AVG(X)OVER() AS DECIMAL(38,20)) FROM 
(
SELECT 1770.0700000000 AS X FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
)A ;

SELECT CAST(AVG(x) AS DECIMAL(38,20)) FROM
(
SELECT 1770.0700000000 AS X FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
UNION ALL
SELECT 1770.0700000000 FROM SYS_CALENDAR.CALENDAR WHERE DAY_OF_CALENDAR = 1
)A

The first code gives a result of 1770.06999999999999999.......

The second code gives a result of 1770.070000000000000000......