數(shù)據(jù)庫:MySQL 5.7
image.png
create table tmp_test as
select 1 as id ,1 as a ,2 as b ;
select * from tmp_test
-- 寫錯(cuò)了 卻可以執(zhí)行 且a的值變?yōu)? (正確是用逗號(hào))
update tmp_test
set a = 2 and b= 3
where id = 1
image.png
SQL 解釋器會(huì)嘗試評(píng)估 a = 2 and b = 3 這個(gè)表達(dá)式
使用了 AND 實(shí)際上會(huì)將其視為一個(gè)條件表達(dá)式 琢蛤,并嘗試將其轉(zhuǎn)換為布爾值
在 SQL 中坷衍,布爾值 TRUE 常常會(huì)被隱式轉(zhuǎn)換為數(shù)值 1,而 FALSE 轉(zhuǎn)換為 0
image.png