首页 > 其他 > 详细

根据条件合并结果集

时间:2016-10-14 09:55:53      阅读:235      评论:0      收藏:0      [点我收藏+]

原文 根据条件合并结果集

第一个查询是将三个表中的列通过键连接起来,并将查询结果重命名为别名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

 

根据条件合并结果集

原文:http://www.cnblogs.com/arxive/p/5959075.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!