频道栏目
首页 > 资讯 > Oracle > 正文

oracle分页、mysql分页、删除重复记录及简单的sql的查询教程

18-06-16        来源:[db:作者]  
收藏   我要投稿

新建三张表:t_student(id,stuname,sex,age,areaid,classid)

t_area(id,areaname)

t_class(id,className)

--查询出学生名以及学生所在班级名select s.stuname,s.sex,s.age,c.classname from t_student s left join t_class c on s.classid=c.id;--查询年龄在18-30之间的女生姓名以及所在的班级名select s.stuname,s.sex,s.age,c.classname from t_student s left join t_class c on s.classid=c.id where s.age between 18 and 30 and s.sex=0;--查询年龄在18-30之间的山东女生姓名以及所在的班级名并且按照年龄进行升序排列select s.stuname,s.sex,s.age,c.className from t_student s left join t_area a on s.areaid=a.id left join t_class c on s.areaid=c.id where s.age between 18 and 30 and s.sex=0 order by s.age asc;--查询年龄在18-30之间的姓张的女生姓名以及所在的班级名并且按照年龄进行升序排列select s.stuname,c.classname,s.age,s.sex from t_student s inner join t_class c on s.classid=c.id where s.age between 18 and 30 and s.sex=0 and s.stuname like '张%' order by s.age asc;--查询男女生各自的人数以及平均年龄select sex,count(*),avg(age) from t_student group by sex;--查询各班男女生的人数以及平均年龄select s.sex,count(*),avg(s.age),c.classname from t_student s left join t_class c on s.classid=c.id group by s.sex;--查询各班中各个地区男女生人数select count(*),s.sex,a.areaname,c.classname from t_student s left join t_area a on s.areaid=a.id left join t_class c on s.classid=c.id group by s.sex,a.areaname,c.classname;--删除学生表中的重复记录[姓名,年龄,地区相同的]delete from t_student s left join t_area a on s.areaid=a.id where s.id Not In(Select Max(s.ID),a.areaname,s.stuname,s.age From t_student left join t_area a Group By a.areaname,s.stuname,s.age);

-----------delete from t_student whereId not in(select t.* from (select max(s.id) from t_student s group by s.age,s.stuname,s.areaid) t )

--删除山西姓李的未成年男生delete from t_student where id in(select id from t_area where areaname='山西') and stuname like'李%' and age>18 and sex=1

--oracle的分页,查询未成年的男生并按照年龄进行倒叙排列,并进行分页。【每页有13条数据,查询第33页的数据】select * from (select s.*,rownum rn from(select stuname,sex,age from t_student where sex = 1 and age < 18 Group by age desc) swhere rownum <= 442)where rn >= 430;

--mysql的分页,查询未成年的男生并按照年龄进行倒叙排列,并进行分页。【每页有13条数据,查询第33页的数据】select s.* from(select stuname,sex,age from t_student where sex = 1 and age < 18 Group by age desc ) slimit 429,13

相关TAG标签
上一篇:Spring Cloud微服务分布式云架构源码结构
下一篇:Spring Cloud Consul解析
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站