Mysql操作——DQL-2-條件查詢

條件查詢

條件查詢就是在查詢時給出where子句,在where子句中可以使用一些運算符及關鍵字。

\color{red}{常用條件查詢符及關鍵字}

=(等于)、!=(不等于)、<>(不等于)、<(小于)、<=(小于等于)、>(大于)、>=(大于等于)
between....and;值在什么范圍
in(set);固定的范圍值
is null;(為空)
is not null; (不為空)
and 與
or 或
not 非

使用
  1. 查詢性別為男,且年齡為20的學生記錄
mysql> select * from students where gender='男' and age=20;
  1. 查詢學號為2,或者名為denve的學生記錄
mysql> select * from students where id=2 or name='denve';
  1. 查詢學號為1,2,5,的學生記錄
#方法一
mysql> select * from students where id=1 or id=2 or id=5;
#方法二
mysql> select * from students where id in(1,2,5);

4.查詢年齡為Null的學生記錄

mysql> select * from students where name is null;

5.查詢年齡不為Null的學生記錄

mysql> select * from students where name is not null;

6.查詢性別非男的學生記錄

mysql> select * from students where gender!='男';

7.查詢年齡在18到20歲之間的學生記錄

#方法一
mysql> select * from students where age>=18 and age<=20;
#方法二
mysql> select * from students where age between 18 and 20;
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容