--Employee ID, Orders Processed, Sort by processed
SELECT EmployeeID, Count(OrderID) as TotalOrders
    FROM Orders
    GROUP BY EmployeeID
    ORDER BY TotalOrders DESC;

--Get top 5
SELECT * FROM (
        SELECT EmployeeID, Count(OrderID) as TotalOrders
        FROM Orders
        GROUP BY EmployeeID
        ORDER BY TotalOrders DESC)
    WHERE rownum <= 5;

--Retrieve most expensive order
SELECT * FROM (
        SELECT OrderID, Sum(UnitPrice * Quantity * (1 - Discount)) AS Expense
        FROM Order_Details
        GROUP BY OrderID
        ORDER BY Expense DESC)
    WHERE rownum <= 1;

--10 bestselling products
SELECT * FROM (
        SELECT P.ProductName, Sum(O.Quantity) AS Sales, Rank() OVER
            (ORDER BY Sum(O.Quantity) DESC)
            AS RNK
        FROM Products P, Order_Details O
        WHERE P.ProductID = O.ProductID
        GROUP BY P.ProductName
        ORDER BY Sales DESC)
    WHERE RNK <= 10;

