I need to find the Stock Item with the greatest profit margin, however am unsure on how to do so as this was calculated within the query and not taken from a table. My script is as follows (Using Oracle 11g), and currently returns several stock items when I need only one. Please help
SELECT (UPPER(Orderline.StockID) || ' ' || INITCAP(StockDesc)) AS "Item",
CategoryDesc AS "Category",
LocationCity AS "Warehouse",
Quantity AS "Number Sold",
TO_CHAR(Quantity * UnitPrice) AS "Total Income",
TO_CHAR(Quantity * UnitCost) AS "Total Cost",
TO_CHAR((Quantity * UnitPrice) - (Quantity * UnitCost)) AS "Profit"
FROM Orderline INNER JOIN
(Stock INNER JOIN
("CATEGORY" INNER JOIN Warehouse
ON "CATEGORY".Warehouse = Warehouse.WarehouseID)
ON Stock.ItemCategory = "CATEGORY".CategoryID)
ON Orderline.StockID = Stock.StockNo
ORDER BY ((Quantity * UnitPrice) - (Quantity * UnitCost)) DESC;