學(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é)合()使用