成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

MySQL--4查詢

#查詢的基本語法

成都創(chuàng)新互聯(lián)主營祁門網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,祁門h5小程序定制開發(fā)搭建,祁門網(wǎng)站營銷推廣歡迎祁門等地區(qū)企業(yè)咨詢

select * from 表名;
from關(guān)鍵字后面寫表名,表示數(shù)據(jù)來源于是這張表
select后面寫表中的列名,如果是**表示在結(jié)果中顯示表中所有列
在select后面的列名部分,可以使用as為列起別名,這個別名出現(xiàn)在結(jié)果集中
如果要查詢多個列,之間使用逗號分隔

例:
select id,name from students;

消除重復(fù)行

在select后面列前使用distinct可以消除重復(fù)的行
select distinct gender from students;

#條件

使用where子句對表中的數(shù)據(jù)篩選,結(jié)果為true的行會出現(xiàn)在結(jié)果集中
語法如下:
select * from 表名 where 條件;
比較運算符

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

例:
查詢編號大于3的學(xué)生
select * from students where id>3;

查詢編號不大于4的科目
select * from subjects where id<=4;

查詢姓名不是“黃蓉”的學(xué)生
select * from students where sname!='黃蓉';

查詢沒被刪除的學(xué)生
select * from students where isdelete=0;

#邏輯運算符

and
or
not

查詢編號大于3的女同學(xué)
select * from students where id>3 and gender=0;

查詢編號小于4或沒被刪除的學(xué)生
select * from students where id<4 or isdelete=0;

#模糊查詢

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

查詢姓黃的學(xué)生
select * from students where sname like "黃%";

查詢姓黃并且名字是一個字的學(xué)生
select * from students where sname like "黃_";

查詢姓黃并且名字是兩個字的學(xué)生
select * from students where sname like "黃__";

查詢姓黃或叫靖的學(xué)生
select * from students where name like "黃%" or sname like "%靖%";

查詢名字中有龍的學(xué)生
select * from students where name like "%龍%";

#范圍查詢

in表示在一個非連續(xù)的范圍內(nèi)

查詢編號是1或3或8的學(xué)生
select * from students where id in(1,3,8);

between ... and ...表示在一個連續(xù)的范圍內(nèi)

查詢學(xué)生是3至8的學(xué)生
select * from students where id between 3 and 8;

查詢學(xué)生是3至8的男生
select * from students where id between 3 and 8 and gender=1;

PS:當一個查詢語句中有多個and時,優(yōu)先匹配between and作為一組,where 語句后自左向右依次匹配,遇到一個between與之后面的and先匹配成一組,最后才是邏輯運算符的and,邏輯運算符的優(yōu)先級較低。

#空判斷

注意:null與''是不同的
判空is null

查詢沒有填寫地址的學(xué)生
select * from students where hometown is null;

判非空is not null

查詢填寫了地址的學(xué)生
select * from students where hometown is not null;

查詢填寫了地址的女生
select * from students where hometown is not null and gender=0;

#優(yōu)先級

小括號,not,比較運算符(與between同級),邏輯運算符
and比or先運算,如果同時出現(xiàn)并希望先算or,需要結(jié)合()使用

文章題目:MySQL--4查詢
當前URL:http://jinyejixie.com/article26/pshicg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、網(wǎng)站內(nèi)鏈、云服務(wù)器、自適應(yīng)網(wǎng)站、營銷型網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)
绥宁县| 安丘市| 丰台区| 通城县| 民乐县| 宽甸| 青铜峡市| 万荣县| 宽甸| 大埔区| 龙胜| 电白县| 镇平县| 潍坊市| 行唐县| 渝北区| 乌兰察布市| 都兰县| 凭祥市| 河北区| 株洲县| 乳源| 建德市| 沐川县| 温宿县| 吴桥县| 调兵山市| 万宁市| 石嘴山市| 偏关县| 武威市| 永宁县| 常熟市| 晋州市| 高雄市| 张掖市| 天峨县| 滨州市| 孙吴县| 江孜县| 三门县|