2016-04-11 67 views
-2
tbi_Customer    tbl_order 
CustId int    orderid int 
Customer no    OrderName varchar(50) 
         CustId int 
+0

你能否也請告訴我們你到目前爲止已經嘗試解決這個問題? –

+0

你是什麼意思的最大訂單?!?!?!?! –

回答

0

試試這個

select top 1 a.customerno,b.totalorder from tbl_Customer as a 
join (select custid,count(custid) as totalorder from tbl_order group by custid) b on a.custid=b.custid 
order by b.totalorder desc 
+1

雖然此代碼可能會回答問題,但提供 有關_why_和/或_how_的其他上下文,它將回答 該問題將顯着提高其長期值 的值。請[編輯]你的答案,添加一些解釋。 –

0

由於沒有OrderAmount類型列,我假設你需要的是訂單的最大數量。

select top 1 
C.[Customer Number], 
count(C.[Customer Number]) as [Number of Orders] 
from tbl_Customer C join tbl_order O 
    on C.CustId = O.CustId 
group by C.[Customer Number] 
order by 2 desc