where字句中可以使用:
1. 比較運算符:> < >= <= <> !=
2. between 80 and 100 值在10到20之間
3. in(80,90,100) 值是10或20或30
4. like 'egon%'
pattern可以是%或_,
%表示任意多字符
_表示一個字符
5. 邏輯運算符:在多個條件直接可以使用邏輯運算符 and or not
1.但條件查詢
# 查詢id大於7的記錄。 select * from employee where id > 7
2.多條件查詢
# 查詢post為'teacher' 並且 salary 大於8000的記錄。 select * from employee where post = 'teacher' and salary > 8000;
3.關鍵字between and
# 查詢salary大於等於20000和salary小於等於30000的記錄。 select * from employee where salary between 20000 and 30000;
4.in
# 查詢age為73或81或28的記錄。 select * from employee where age in (73,81,28);
5.判斷記錄是否為NULL
# 查詢post_comment字段為null的記錄。 select * from employee where post_comment is null; # 查詢post_comment字段不為null的記錄。 select * from employee where post_comment is not null;
6.like(%:匹配任意多個字符。_:匹配任意一個字符)
# 查詢name字段為"jin"開頭的記錄。 select * from employee where name like 'jin%'; # 查詢name字段為"ao"結尾的記錄。 select * from employee where name like '%ao'; # 查詢name字段為"jin"開頭后面有任意3個字符的記錄。 select * from employee where name like 'jin___';
7.正則表達式
# 查詢name字段以al開頭的記錄。 SELECT * FROM employee WHERE name REGEXP '^al';