The pop-up box appears because SalesOrder.PID
references a table SalesOrder
that is not in the from
clause. Presumably you mean SalesOrderProduct
.
You should also use explicit joins in your query, and table aliases for all columns:
SELECT p.PID, p.Code, COUNT(sop.PID) AS Ordered,
SUM(sop.ExtendedPrice) AS [Value],
SUM(sop.NbrItemsRequested) AS Requested
FROM Product as p inner join
SalesOrderProduct as sop
on p.PID = sop.PID
GROUP BY p.PID, p.Code
ORDER BY SUM(sop.NbrItemsRequested);
I'm not sure what you mean by the order by
not working, but I'm guessing that putting the formula in instead of the alias will fix the problem.
Note: the above is guessing as to where ExtendedPrice
and NbrItemsRequested
come from.