有这样两张表,
人员成绩表:id,人员ID,科目id,科目成绩。。。
称号评审表:id,称号id,科目ID,科目成绩,科目分组。。。
分析:一个人可以有多种科目记录,每种科目记录都有一个科目成绩。
一个称号要求有多个科目,以及科目的及格成绩。
一个人如果要获取某个称号,必须具有称号要求的所有科目,且成绩要大于等于称号要求的成绩。
当称号中的某两个科目为一组时,人员只需满足这一组中的一个以及没有组的所有即可。
不要存储过程和函数,要用一个sql语句解决,真正的大牛感兴趣了可以试试!
如果有可用的关键字也可以说说!
参与就有分送!!!
------解决方案--------------------
初步看来 2种获取称号的方式 没什么联系 先考虑分开统计
下面是称号中科目分组的情况 不分组规则也是一样 统计dis_group is null个数
感觉还是比较麻烦 应该还有简单方法的
select person_id,title_id
from
(
select a.person_id,a.course_score,b.title_id,b.dis_group
from t_person_course a,t_title_course b
where a.course_id = b.course_id and a.course_score >= b.course_score and b.dis_group is not null
) t
where 1=1
group by person_id,title_id
having count(*) = (select count(*) from t_title_course where dis_group is not null)
------解决方案--------------------
select c.title_id, c.person_id
from (select distinct a.title_id,
a.course_score,
a.course_id,
b.person_id,
b.course_score
from (select distinct a.TITLE_ID,
a.COURSE_SCORE,
a.course_id,
b.person_id
from t_title_course a, t_person_course b
where a.DIS_GROUP is null) a
left join t_person_course b
on a.course_id = b.course_id
and a.PERSON_ID = b.PERSON_ID
where b.COURSE_SCORE >= a.COURSE_SCORE) c, --检查符合没有组的有哪些PERSON_ID
(select distinct a.title_id,
a.course_score,
a.course_id,
b.person_id,
b.course_score
from (select distinct a.TITLE_ID,
a.COURSE_SCORE,
a.course_id,
b.person_id
from t_title_course a, t_person_course b
where a.DIS_GROUP is not null) a
left join t_person_course b
on a.course_id = b.course_id
and a.PERSON_ID = b.PERSON_ID
where b.COURSE_SCORE >= a.COURSE_SCORE) d --检查符合有组的有哪些PERSON_ID
where c.PERSON_ID = d.PERSON_ID
and c.title_id = d.title_id
------解决方案--------------------