首页 / 更多教程 / 由一条sql语句引发的学习之二
由一条sql语句引发的学习之二
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了由一条sql语句引发的学习之二,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1985字,纯文字阅读大概需要3分钟。
内容图文
![由一条sql语句引发的学习之二](/upload/InfoBanner/zyjiaocheng/890/e7fa16708d3e4831aff81cd4e91e8a91.jpg)
select m.*,case
when m.max_num > n.maxvalue then '被考核' else '正常' end as maxvalue ,
nvl(n.CATEGORY,'其他') from (
select 'didi' x1 ,a.templateid ,b.template_name ,sum(a.num) send_num,count(1) user_num,max(a.num) max_num,trunc(sum(a.num)/count(1)) seg_num
from (
select phone_no, templateid, count(1)num
from math_score
where send_time > trunc(sysdate)
group by phone_no, templateid
having count(1) > $anum) a, school_info b
where a.templateid = b.template_id ${tiaojian}
group by a.templateid,b.template_name
union all
select 'didi',a.templateid,b.template_name ,sum(a.num) send_num,count(1) user_num,max(a.num) max_num,trunc(sum(a.num)/count(1)) seg_num
from (
select phone_no, templateid, count(1)num
from english_score
where send_time > trunc(sysdate)
group by phone_no, templateid
having count(1) > $anum) a, school_info b
where a.templateid = b.template_id ${tiaojian}
group by a.templateid,b.template_name
union all
select 'didi',a.templateid,b.template_name ,sum(a.num) send_num,count(1) user_num,max(a.num) max_num,trunc(sum(a.num)/count(1)) seg_num
from (
select phone_no, templateid, count(1)num
from chinese_score
where send_time > trunc(sysdate)
group by phone_no, templateid
having count(1) > $anum) a, school_info b
where a.templateid = b.template_id ${tiaojian}
group by a.templateid,b.template_name) m ,school_info n
where m.templateid = n.template_id
order by user_num desc;
场景:
求取一个学校内,每个(语文\数学\英语)老师所带学生的班级名、班级总分、班级人数、最高分,平均分、及格率,及格率是否符合正常情况(考核老师)
school_info表字段:老师id、班级、班级人数、及格率...
math_score表字段:老师id、班级、手机号、学生信息、数学成绩...
关键语法解析:
1、NVL函数:从两个表达式返回一个非 null 值。
2、case用法:详细解析
3、from+表名跟from+select语句作用一样。
4、Union和Union All区别:详解
Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;
Union All:对两个结果集进行并集操作,包括重复行,不进行排序;
内容总结
以上是互联网集市为您收集整理的由一条sql语句引发的学习之二全部内容,希望文章能够帮你解决由一条sql语句引发的学习之二所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。