Can anybody tell me why is this query not working?
Select temp.CompanyName from
(
SELECT c.CompanyName, o.OrderID,
YEAR(o.OrderDate) As YEAR,
Sum(od.UnitPrice * od.Quantity) from Orders o
INNER JOIN [Order Details] od
ON o.OrderID = od.OrderID
INNER JOIN Customers c
On c.CustomerID = o.CustomerID
GROUP BY o.OrderId,c.CompanyName, YEAR(o.OrderDate)
) As temp;
It uses Northwind database. If i run it without creating a temporary view i.e if i run the query just contained within round brackets it runs just fine.