我的成绩数据库有时会每天刷新几次,如果没有输入新成绩,则每次都可能是相同的成绩。查询我找到了每个课程编号的每日最高分数,所以现在我只想在它发生变化时找到并显示成绩,表明已经输入了新的成绩。如果有人能指出我正确的方向。谢谢!
select distinct convert(date,GradeDate)'Grade Date',
max(gradescore) 'Grade Score', coursenbr
from resultstbl
group by Gradedate, coursenbr
order by coursenbr
以下是我的结果:
File Date Current Score coursenbr
2014-05-11 92.5 111
2014-05-22 92.5 111
2014-05-24 92.5 111
2014-05-12 NULL 222
2014-05-21 75 444
2014-05-23 75 444
2014-05-26 75 444
2014-05-12 50 333
2014-05-21 80.2 777
2014-05-23 80 888
2014-05-26 80 888
2014-05-27 80 888
答案 0 :(得分:0)
尝试在桌面上使用更新触发器
答案 1 :(得分:0)
查询基于您的resultstbl。 输出有CurrentScore,LastScore和一个位标志,表示自上次记录以来分数是否变化。
尝试
SELECT *
, CASE
WHEN (sub.[Current Score] <> sub.[Last Score])
THEN CAST(1 as bit)
ELSE CAST(0 as bit)
END
AS [Score Changed]
FROM
(
SELECT [File Date]
, [Current Score]
, (
SELECT TOP 1 b.[Current Score]
FROM resultstbl b
WHERE b.[File Date] < a.[File Date]
AND b.coursenbr = a.coursenbr
ORDER BY b.[File_Date] DESC
)
AS [Last Score]
, [coursenbr]
FROM resultstbl a
) sub