学习第十五天
基础查询
select name,age from stu;
查询名字和年龄
DISTINCT
去除重复信息
select * from stu;
select name,math as 数学成绩, engilsh as 英语成绩 from stu;
查询姓名英语数学成绩
条件查询
select * from stu where age>20;
select * from stu where age>=20;
select * from stu where age>=20 && age <= 30;
select * from stu where age>=20 and age <= 30;
select * from stu where age BETWEEN 20 and 30;
select * from stu where heire_date BETWEEN '1998-09-01'and '1999-09-01';
select * from stu where age != 18;
select * from stu where age <> 18;
都表示不等于
select * from stu where age= 18 || age = 20 || age = 22;
select * from stu where age= 18 or age = 20 or age = 22;
select * from stu where age in (18,20,22)
注意:null值的比较不能使用= != 。需要使用is 或者is not select * from stu where english = null; --不行的 select * from stu where english is null;
模糊查询
select * from stu where name like '马%';
select * from stu where name like '-马%';
select * from stu where name like '%德%';
排序查询
select * from stu ORDER BY age ;
select * from stu order by math desc;
select * from stu order by math desc,english asc;
分组查询
聚合函数
select count (id) from stu ;
select max(math) from stu;
select sum (math) from stu;
select avg (math) from stu;
select sex,avg(math) from stu group by sex;
select sex,avg(math) , count(*) from stu group by sex;
select sex,avg(math) , count(*) from stu where math > 70 group by sex;
select sex,avg(math) , count(*) from stu where math > 70 group by sex having count ()>2;
分页查询
select * from stu limit 0 , 3;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现