Guess here:
SELECT [Day], [Hour], [DayN], AVG(Totals) AS [Avg] FROM ( SELECT [Day] = DATENAME(WEEKDAY, [time]), [DayN] = DATEPART(WEEKDAY, [time]), [Hour] = DATEPART(HOUR, [time]), Totals = COUNT(*) FROM dbo.[log] WHERE [code] = 'tib_imp.8' GROUP BY DATENAME(WEEKDAY, [time]), DATEPART(WEEKDAY, [time]), DATEPART(HOUR, [time]) ) AS q GROUP BY [Day], [Hour], [DayN] ORDER BY DayN;
Again, without data, I could again throw a handful of dirt on the wall and hope that it gets stuck, but maybe you need:
SELECT [Day], [Hour], [DayN], AVG(Totals) AS [Avg] FROM ( SELECT w = DATEDIFF(WEEK, 0, [time]), [Day] = DATENAME(WEEKDAY, [time]), [DayN] = DATEPART(WEEKDAY, [time]), [Hour] = DATEPART(HOUR, [time]), Totals = COUNT(*) FROM dbo.[log] WHERE [code] = 'tib_imp.8' GROUP BY DATEDIFF(WEEK, 0, [time]), DATENAME(WEEKDAY, [time]), DATEPART(WEEKDAY, [time]), DATEPART(HOUR, [time]) ) AS q GROUP BY [Day], [Hour], [DayN] ORDER BY DayN;
This will also result in integer averages, so you might need to assign the Totals alias in the internal DECIMAL query (something, something).