根据条件合并结果集

╄→гoц情女王★ 提交于 2019-11-26 16:36:00

原文 根据条件合并结果集

第一个查询是将三个表中的列通过键连接起来,并将查询结果重命名为别名aaa;

最后将两个查询的结果集aaa,bbb,通过 aaa.student_id = bbb.studentid连接起来。

 

select aaa.*,bbb.required,bbb.elective from
(select c.student_id,c.chinese_name,c.user_class, sum(decode(b.coursetype,1,a.credit,0)) get_required_total,sum(decode(b.coursetype,0,a.credit,0)) get_elective_total, sum(decode(b.coursetype,1,a.coursecredit,0)) reg_required_total,sum(decode(b.coursetype,0,a.coursecredit,0)) reg_elective_total
from sm_course_student a,sm_courses b,sm_students c
where a.course_id=b.courseid and a.student_id=c.student_id  and c.user_class like '10SH%' group by c.student_id,c.chinese_name,c.user_class

)aaa,
(select  studentid,required,elective from sm_school_roll where classname like '10SH%'

)bbb
where aaa.student_id = bbb.studentid

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!