Saturday, April 26, 2014

what's wrong with my code?

Again you have not given clear details like to table structure for frieight field.


Still check below query as we dont have table structure of anyone,



SELECT TOP 1 e.EmployeeID, (reqTotalOrderPrice + ORD.Freight) as TotalAmount, TotalOrders
FROM ( SELECT e.EmployeeID, (SUM(TotalOrderPrice)*0.1) AS reqTotalOrderPrice, COUNT(o.OrderID) as TotalOrders
FROM Employees e
INNER JOIN Orders o
ON o.EMployeeID = e.EmployeeID
INNER JOIN (SELECT OrderID,SUM((UnitPrice * Quantity) - Discount) AS TotalOrderPrice
FROM [Order Details]
GROUP BY OrderID
)oi
ON oi.OrderID = o.OrderID
GROUP BY e.employeeid
) RSET
INNER JOIN Orders ORD ON RSET.EmployeeID = ORD.EmployeeID
ORDER BY reqTotalOrderPrice DESC,TotalOrders ASC


No comments:

Post a Comment