空數據我想了解處理的黑斑羚
我使用下表
╔════╦══════════════╦══════════╗
║ id ║ name ║ salary ║
╠════╬══════════════╬══════════╣
║ 1 ║ cde ║ 5636 ║
║ 2 ║ asd ║ 148 ║
║ 3 ║ pwe ║ null ║
║ 4 ║ lmn ║ 959 ║
╚════╩══════════════╩══════════╝
當我執行以下查詢
在因帕拉算術運算的行爲
select salary+20 as sum1 from table where id=3;
它返回我
|sum1
---|-----
1 |NULL
當我運行在列總和與
select sum(salary) as sum1 from table;
|sum1
---|-----
1 |6743
我無法瞭解相同的算術運算表現不同
按照你的理論,當我這樣做從表總和(工資),其中id = 3應該忽略空並打印總和爲zero.But還是它返回NULL – sri
啊我看你可能會感到困惑。因此,在sum()中,如果數據庫中有有效值,它將返回這些有效值的總和。但是,如果你試圖總結無效的值,即。 'a + null + 1.144es'或者它會抱怨並返回'null'。但是'10 + null + 20 + a'會返回'30'。 – Francisco
10 + null + 20 + a也返回NULL – sri