当前位置: 首页 > news >正文

单表查询习题

建表语句:

create table student33(id int(4),age int(8),sex int(4),
name varchar(20),class int(4),math int(4));
INSERT into student33 VALUES (1,25,1,'zhangsan',1833,90),
(2,25,1,'lisi',1833,67),(3,28,0,'xiaowang',1835,79),
(4,35,1,'xiaoliu',1835,96),(5,27,0,'xiaoli',1833,86),
(6,32,1,'xiaochen',1835,48),(7,22,1,'wangwu',1834,70),
(8,31,0,'xiaoqi',1825,88), (9,27,0,'xiaoqi',1833,74),
(10,27,1,'niuqi',null,74)
select *from student33

1、查询1833班信息的2,4行的数据

select * from student33 where id in(
(select id from student33 limit 1,1),(select id from student33 limit 3,1)
)

2、显示班级为空的id和姓名、和数学分数

select id,name, math from student33 where class is null

3、统计每个班级人数

select count(id),class from student33 group by class

4、取1833班数学成绩最大的ID年龄和姓名

select id,age,name from student33 where class=1833 and math=(select max(math) from student33 where class=1833)

5、求数学分最小的班级 ID年龄和姓名

select class,id,age,name from student33 where math=(select min(math) from student33)

6、求1833班数学分总和

select sum(math) from student33 where class=1833

7、求所有班级分数总和

select sum(math) from student33 where class is not null

8、求年纪最大的班级并显示班级年龄和姓名分数

select class,age,name,math from student33 where age=(select max(age) from student33)

9、统计sex 1和0个总数

select count(sex) from student33 group by sex

10、求出每个班级年纪平均数

select avg(age),class from student33 group by class

11、求出1835班年纪的平均数

select avg(age) from student33 where class=1835

12、求出1833班年纪的平均数

select avg(age) from student33 where class=1833

13、将所有数据按照年纪进行降序后显示年纪姓名和班级

select age,name,class from student33 order by age desc

14、将所有数据按照年纪升序显示年纪姓名班级和数学分数

select age,name,class,math from student33 order by age asc

15、按照班级将进行分组

select class,count(*) from student33 group by class

16、根据age字段进行降序排序;

select *from student33 order by age desc

17、根据math字段进行升序排序,并显示前5行所有数据;

select *from student33 order by math asc limit 5

18、把lisi的数学成绩改为69分

update student33 set math=69 where name="lisi"
select * from student33

19、查找性别不为1的所有数据

select * from student33 where sex!=1

20、只显示表中姓名,且将相同的姓名名称去重

select distinct name from student33

21、统计表中行数

select count(*) from student33

22、统计年纪在27岁的有多少

select count(*) from student33 where age=27

23、统计年纪大于25小于35的有多少

select count(*) from student33 where age>25 and age<35

24、求数学分总和

select sum(math) from student33

25、求分数最小

select min(math) from student33

26、求平均分

select avg(math) from student33

27、只显示3-8行的数据

select * from student33 limit 2,6

28、查找姓名尾号为qi的所有数据

select * from student33 where name like "%qi"

29、查询姓名开头为xiao的所有数据

select * from student33 where name like "xiao%"

30、查询中间值为ao开头的所有数据

select * from student33 where name like "%ao%"

http://www.jsqmd.com/news/678201/

相关文章:

  • 别再只懂TF-IDF了!手把手教你用Python实现BM25算法(附完整代码与调参技巧)
  • 2026上海办公区域保洁推荐榜:上海日常保洁,企业保洁服务,会展保洁服务,公司保洁服务,公司开荒保洁,优选指南! - 优质品牌商家
  • 如何快速掌握RPFM:从新手到模组专家的完整指南
  • 前端构建速度优化方法
  • MSVBVM50.DLL文件丢失怎么办? 免费下载方法分享
  • 2026年3月水泥管供应商推荐,冷拔丝/混凝土涵管/水泥管/水泥制品/环保化粪池/成品检查井,水泥管品牌推荐 - 品牌推荐师
  • 工行科技岗面试官亲述:我们如何在2对1面试中,用‘限定问题’帮你理清思路?
  • Dism++终极指南:掌握Windows系统维护的完整解决方案
  • NPK文件格式深度解析:逆向工程网易NeoX引擎资源提取技术方案
  • 从‘拒绝访问’到注册成功:深度复盘Win10/Win11下MSCOMM控件安装的全流程踩坑记录
  • VCS后仿X态清理实战:从Memory到DFT,手把手教你搞定Pre-PR仿真的那些‘幽灵’信号
  • 流量图 - 小镇
  • 终极微信聊天记录导出方案:3步永久保存你的珍贵对话
  • 仅限首批200名开发者获取:.NET 11 AI加速内测SDK + 12个工业级推理Pipeline源码(含医疗影像分割/金融时序预测双场景)
  • 汉语汉字:人类文明中最优秀的语言文字
  • Mac新手必看:Axure RP 9安装后提示‘已损坏’的终极修复指南(附最新Ventura系统解决方案)
  • EF Core 10向量扩展实战面试题精讲:从Cosine相似度到ANN索引优化,95%候选人答不全第7题!
  • 避开IMU航向漂移坑:手把手教你融合Livox Avia点云与BMI088数据做SLAM
  • 四川大学自动化考研深度解析:从报考趋势到备考策略的五年全景图
  • Qt5/6实战:用QPainter在Widget上画个带边框和填充色的矩形(附源码)
  • 别再傻傻分不清了!KVM、Xen、Hyper-V、VMware四大虚拟化技术,到底该选哪个?
  • 别再死记硬背Riccati方程了!用‘能量’和‘成本’的视角重新理解LQR控制
  • 别再傻傻分不清了!Unity的Albedo和UE5的Base Color到底有啥区别?
  • 3步掌握DeepXDE:快速上手科学机器学习核心库
  • Excel跑不动?Python不会写?这个Skill一键搞定数据处理
  • Zynq SoC与RTOS集成开发实战:NeoPixel控制器实现
  • RPG Maker MV/MZ资源解密终极指南:快速恢复游戏资源的免费工具
  • 别再傻等Gradle下载了!手把手教你用本地文件解决Android Studio的Could not install Gradle报错
  • 别再凭感觉画差分线了!手把手教你用Polar SI9000搞定100Ω阻抗匹配(附实战案例)
  • 私有化视频会议系统/视频直播点播EasyDSS一体化音视频平台打造全链路企业培训解决方案