国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL查詢條件常見用法詳解

2020-01-18 20:39:27
字體:
來源:轉載
供稿:網友

本文實例講述了MySQL查詢條件常見用法。分享給大家供大家參考,具體如下:

條件

使用where子句對表中的數據篩選,結果為true的行會出現在結果集中

語法如下:

select * from 表名 where 條件;

例:

select * from students where id=1;

where后面支持多種運算符,進行條件的處理

比較運算符
邏輯運算符
模糊查詢
范圍查詢
空判斷

比較運算符

等于: =
大于: >
大于等于: >=
小于: <
小于等于: <=
不等于: != 或 <>

例1:查詢編號大于3的學生

select * from students where id > 3;

例2:查詢編號不大于4的學生

select * from students where id <= 4;

例3:查詢姓名不是“黃蓉”的學生

select * from students where name != '黃蓉';

例4:查詢沒被刪除的學生

select * from students where is_delete=0;

邏輯運算符

and
or
not

例5:查詢編號大于3的女同學

select * from students where id > 3 and gender=0;

例6:查詢編號小于4或沒被刪除的學生

select * from students where id < 4 or is_delete=0;

模糊查詢

like
%表示任意多個任意字符
_表示一個任意字符

例7:查詢姓黃的學生

select * from students where name like '黃%';

例8:查詢姓黃并且“名”是一個字的學生

select * from students where name like '黃_';

例9:查詢姓黃或叫靖的學生

select * from students where name like '黃%' or name like '%靖';

范圍查詢

in表示在一個非連續的范圍內

例10:查詢編號是1或3或8的學生

select * from students where id in(1,3,8);

between … and …表示在一個連續的范圍內

例11:查詢編號為3至8的學生

select * from students where id between 3 and 8;

例12:查詢編號是3至8的男生

select * from students where (id between 3 and 8) and gender=1;

空判斷

注意:null與''是不同的

判空is null

例13:查詢沒有填寫身高的學生

select * from students where height is null;

判非空is not null

例14:查詢填寫了身高的學生

select * from students where height is not null;

例15:查詢填寫了身高的男生

select * from students where height is not null and gender=1;

優先級

優先級由高到低的順序為:小括號,not,比較運算符,邏輯運算符

and比or先運算,如果同時出現并希望先算or,需要結合()使用

更多關于MySQL相關內容感興趣的讀者可查看本站專題:《MySQL查詢技巧大全》、《MySQL常用函數大匯總》、《MySQL日志操作技巧大全》、《MySQL事務操作技巧匯總》、《MySQL存儲過程技巧大全》及《MySQL數據庫鎖相關技巧匯總

希望本文所述對大家MySQL數據庫計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤庆县| 延庆县| 多伦县| 桦南县| 定安县| 榆树市| 丽江市| 禹城市| 密云县| 克什克腾旗| 当涂县| 罗山县| 南溪县| 蒙自县| 宜州市| 图木舒克市| 泾阳县| 金川县| 镇平县| 项城市| 成安县| 大渡口区| 南乐县| 巴林左旗| 柘城县| 新丰县| 科尔| 沁源县| 赫章县| 化德县| 翁牛特旗| 长治县| 泾阳县| 黄冈市| 辽中县| 中宁县| 泗阳县| 久治县| 乐东| 彰化县| 阿拉善左旗|