mysql_where條件


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';

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM