Запрос: с учетом только итальянских маршрутов, для каждой категории товаров и для каждого года
SQL:
SELECT
gc.GoodCategory,
tm.Month,
tm.Year,
SUM(ro.Income) / COUNT(DISTINCT tm.Date),
SUM(ro.Income) OVER (PARTITION BY gc.GoodCategory, tm.Year
ORDER BY tm.Month ROWS UNBOUNDED PRECEDING)
FROM FactRoutes ro,
DimLocation dp,
DimLocation ds,
DimGoodCategory gc,
DimTime tm
WHERE ro.DepartureID = dp.LocationID
AND ro.DestinationID = ds.LocationID
AND ro.GoodCategoryID = gc.GoodCategoryID
AND ro.GoodTimeID = tm.GoodTimeID
AND dp.State = 'Italy'
AND ds.State = 'Italy'
GROUP BY gc.GoodCategory,
tm.Month,
tm.Year;
Но с ошибкой ниже
Column 'FactRoutes.Income' is invalid in the select list
because it is not contained in either an aggregate function
or the GROUP BY clause.
какой лучший способ справиться с этим?