我有這個疑問:SQL:左連接和金額:算術溢出錯誤將表達式轉換爲數據類型爲int
select p.UserName, sum(b.PercentRials) as amount, sum(r.Amount) as Pays
from bills b inner join UserProfiles p on b.PayerUserName=p.UserName
left outer join PayReceipts r on p.UserName=r.UserName
where p.[Percent]>0 and b.PayDate>'2014-11-20'
group by p.UserName
我得到這個錯誤,運行時:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
Warning: Null value is eliminated by an aggregate or other SET operation.
我能理解外連接導致此錯誤,因爲當我刪除最後一筆總和時,它運行正常。但我記得做了這樣的查詢,得到NULL
在外連接表上求和。
我該怎麼辦?
警告誤導我。我認爲外部連接是原因,我預計「支付」列值要小得多。謝謝。 – Mahmoodvcs