mySql and與or的使用

幾天前寫個語句用到好幾個條件,用了and與or感覺很繁瑣,現在介紹個新寫法,與大家一起進步。

select * from table where (id=1 or id=2) and price>=10;

則這條語句執行的是id=1或id=2,並且price大於等於10。等同於

select * from table where id = 1 and price >= 10 or id = 2 and price >=10;



發佈了27 篇原創文章 · 獲贊 17 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章