where 條件字句
搜尋條件可由一個或多個邏輯表示式組成 , 結果一般為布林值
邏輯運運算元
運運算元 | 語法 | 描述 |
---|
and && | a and b a && b | 邏輯與 兩個為真, 結果為真 |
or || | a or b a || b | 邏輯或 一個為真, 結果為真 |
not ! | not a !a | 邏輯非 真為假, 假為真 |
SELECT `name`,`sex` FROM student
SELECT `NAMe`, `address` FROM student WHERE `NAME` >= 95 AND `NAME`<= 100
SELECT `NAMe`, `address` FROM student WHERE `NAME` >= 95 && `NAME` <= 100
SELECT `name`,`address` FROM student WHERE `name` BETWEEN 95 AND 100
SELECT `NAMe`, `address` FROM student WHERE `NAME` != 1 AND `NAME` < 10
SELECT `NAMe`, `address` FROM student WHERE NOT `NAME` = 100 AND `NAME` > 90
模糊查詢: 比較運運算元
運運算元 | 語法 | 描述 |
---|
is null | a is null | 如果a為null, 結果為真 |
is not null | a is not null | 如果a不為null, 結果為真 |
between and | 3 between 1 and 5 | 如果 3 在 1 和 5 之間, 結果為真 |
Like | a like b | sql匹配, 如果a匹配b, 結果為真 |
In | a in (abcd, pdosa, …) | 若 a 在 (abcd, pdosa, …) 中, 結果為真 |
SELECT `name` FROM student WHERE `name` LIKE '張%'
SELECT `name` FROM student WHERE `name` LIKE '張_'
SELECT `name` FROM student WHERE `name` LIKE '張__'
SELECT `name` FROM student WHERE `name` LIKE '%張%'
SELECT `id`,`name` FROM student WHERE `id` IN (1,2,3)
SELECT `id`,`name`,`address` FROM student WHERE `address` IN ('北京')
SELECT `name`,`address` FROM student WHERE `address`='' OR `address` IS NULL
SELECT `name`,`address`,`birthday` FROM student WHERE `birthday` IS NOT NULL
SELECT `name`,`address`,`birthday` FROM student WHERE `birthday` IS NULL