7.1-條件查詢

學(xué)生表:

01.png

班級表:

02.png

1.使用 as 給字段起別名

select id as 序號, name as 名字, gender as 性別 from students;

2.通過 as 給表起別名

select s.id,s.name,s.gender from students as s;

3.查詢編號大于3的學(xué)生

select * from students where id > 3;

4.查詢編號大于3的女同學(xué)

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

5.模糊查詢

關(guān)鍵字:like
%表示任意多個任意字符
_表示一個任意字符

1)查詢姓黃的學(xué)生

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

6.范圍查詢

1)查詢編號是1或3或8的學(xué)生

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

2)查詢編號為3至8的學(xué)生

select * from students where id between 3 and 8;

3)查詢 編號 不是 3至8的學(xué)生

select * from students where id not between 3 and 8;

7.空判斷

1)查詢沒有填寫身高的學(xué)生

select * from students where height is null;

注意:null與''是不同的

8.優(yōu)先級

優(yōu)先級由高到低的順序為:小括號,not,比較運(yùn)算符,邏輯運(yùn)算符
and比or先運(yùn)算,如果同時出現(xiàn)并希望先算or,需要結(jié)合()使用

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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