2015-11-06 142 views
-1

我必須從一個客戶那裏得到所有的訂單,然後得到訂單的總和,然後得到最大訂單。 我無法使用排序和限制。 我得到的結果,但我不能讓化妝之和最大的正常工作Max和Sum mysql

這裏是我當前的查詢:

SELECT SUM(Qty * UnitPrice) AS Total FROM `Details` 
WHERE ONo IN (
    SELECT Orders.Ono 
    FROM Orders, Customers 
    WHERE Customers.FName = 'Charles' AND Customers.LName = 'Xavier' AND Customers.CNo = Orders.CNo 
    GROUP BY Orders.ONo 
) 
GROUP BY ONo 

Total 
7.50 
20.99 
54.47 
49.98 
8.00 
+0

是完全相同。我應該從我引用的樣本表(54.47) –

+0

'ORDER BY SUM(Qty * UnitPrice)DESC LIMIT 1'? –

+0

@GiorgosBetsos不允許使用極限 –

回答

0

請嘗試:

SELECT MAX(Total) as MaxTotal FROM (<your query comes here>) AS T