学生信息userInfo表结构:
学生信息userInfo表数据:
方法1:
select * from userInfo a
where (select count(*)from userInfo b where b.major = a.major and b.age>=a.age )<=2 order by major, age desc;
查询结果:
方法2:
select * from userInfo a where a.id in
(select top 2 id from userInfo b where b.major = a.major order by age desc) order by major, age desc
查询结果:
本文探讨了在学生信息数据库中使用两种方法进行高效查询的实现与比较,旨在优化查询效率并展示查询结果的组织方式。
766

被折叠的 条评论
为什么被折叠?



