--如果是所有课程的旷课次数加起来不超过三次,不用触发也可以实现! select [学号],[姓名],(case when [旷课次数]>3 then '不能评为优秀学生' else '可以奖评优秀学生' end) as [奖评状态] from( select [学号],[姓名],count(*) as [旷课次数] from [考勤表] group by [学号],[姓名] )temp
select 学号,学生姓名 from 考勤表 where 出勤状况='a3' group by 学号,学生姓名 having count(*)>=3
select 学号 from 考勤表 WHERE 出勤状况='a3' group by 学号 having(COUNT(*)>=3)-- 这些学生是不能的
直接SQL语句即可.select 学号,学生姓名 from 考勤表 where 出勤状况 = 'a3' group by 学号,学生姓名 having count(1) >= 3
旷课次数超过3次应该是统计时候的条件吧,那直接SQL语句里WHERE后面跟就行了,没必要用触发器。
select 学号,学生姓名 from 考勤表 where cout(出勤状况) = 'a3' group by 学号 having count(*)>=3
select 学号,学生姓名,case when (select count(1) from 考勤表 where 出勤状况='a3')>3 then '优秀评选' end '非优秀学生' from 考勤表
不需要触发器呀?
--如果是所有课程的旷课次数加起来不超过三次,不用触发也可以实现!
select [学号],[姓名],(case when [旷课次数]>3 then '不能评为优秀学生' else '可以奖评优秀学生' end) as [奖评状态]
from(
select [学号],[姓名],count(*) as [旷课次数]
from [考勤表]
group by [学号],[姓名]
)temp
select 学号 from 考勤表 WHERE 出勤状况='a3' group by 学号 having(COUNT(*)>=3)-- 这些学生是不能的
select 学号,学生姓名 from 考勤表 where cout(出勤状况) = 'a3'
group by 学号 having count(*)>=3
select 学号,学生姓名,case when (select count(1) from 考勤表 where 出勤状况='a3')>3 then '优秀评选' end '非优秀学生' from 考勤表