基础查询:
select name,age from stu; -- 查两列
select * from stu; -- 查全部,不推荐
select distinct address from stu; --查一列去除重复数据
select name,math as 数学成绩,english as 英语成绩 from stu; -- 给列起别名
select name,math 数学成绩,english 英语成绩 from stu; --as可以省略
条件查询:
大于/小于:
select * from stu where age>20; -- 大于20
大于等于/小于等于:
select * from stu where age>=20; -- 大于等于20
等于:
select * from stu where age=20; -- 等于20,注意是一个等号
不等于:
select * from stu where age!=20; -- 不等于20
select * from stu where age<>20; -- 不等于20,<>和!=作用相同
与:
select * from stu where age>=20 && age<=30; -- 大于等于20并且小于等于30
select * from stu where age>=20 and age<=30; -- &&与and作用一样
特例:between ...and...:
select * from stu where age between 20 and 30; -- between...and...与&&与and作用一样
或:
select *from stu where age=10 or age=20 or age=30;
特例:in
select *from stu where age in (10,20,30)
null:
select *from stu where english is null; -- 查空数据
select *from stu where english is not null; -- 查不为空的数据
标签:20,--,age,查询,stu,条件,DQL,where,select From: https://www.cnblogs.com/dahuilang21/p/17161731.html