| 发表于:2007-07-21 23:31:261楼 得分:0 |
先把第一问的答案奉献给大家! 1.先求出总人数 select count(distinct studentid) as 总人数 from scorenew 结果=5 2.再求出考试科目最终有不及格的个数。 select studentid, result from (select studentid, classname, result, testdate from scorenew t where not exists (select 1 from scorenew where studentid = t .studentid and classname = t .classname and testdate > t .testdate)) a group by studentid, result having (result = 'f ') 结果显示 2002102 f 改成如下语句 select count(distinct studentid) as 不及格人数 from (select studentid, result from (select studentid, classname, result, testdate from scorenew t where not exists (select 1 from scorenew where studentid = t .studentid and classname = t .classname and testdate > t .testdate)) a group by studentid, result having (result = 'f ')) having (result = 'f ') 显示: 不及格人数 1 所以合格人数=5-1=4 | | |
|