我有一个每周出勤表“出席”或“缺席”
并需要将其更改如下,并附上原因:
如果一个人整整一个月都没有参加,那么他/她在该月之前缺席的几周内将被更改为“辍学”,直到他重新参加。
我已经尝试使用 SQL 来检查“条纹”检查数月的综合出勤率,但无法让“辍学”正确。任何帮助将不胜感激。
使用具有 1 作为 "Absent" 和 0 作为 "Present" 的示例 SourceData ,我使用了以下 SQL 但有一些错误
/* Calculate RunGroup */
SELECT WeekNum, Abs_Status, (SELECT COUNT(*) FROM [SourceData] G WHERE G.Abs_Status <> GR.Abs_Status AND G.WeekNum <= GR.WeekNum) as RunGroup
INTO [RunGroup]
FROM [SourceData] GR;
GO
/* Determine how many weeks in each run */
SELECT Abs_Status, MIN(WeekNum) as StartDate, MAX(WeekNum) as EndDate, COUNT(*) as Games
INTO [WeeksinRun]
FROM [RunGroup] A GROUP BY Abs_Status, RunGroup ORDER BY Min(WeekNum);
GO
/****** What to mark as Dropouts ******/
SELECT [StartDate]
,[EndDate]
INTO [WeekstoUpd]
FROM [WeeksinRun] a,[SourceData] b, [SourceData] c
where a.[StartDate] = b.[Weeknum]
and a.[EndDate] = c.[Weeknum]
and b.[MONTH] <> c.[MONTH]
and a.Abs_Status = '1'
and a.[StartDate] <> '2013 Week 01';
GO
/****** Update Dropout Weeks ******/
update [SourceData]
set [SourceData].[Abs_Status] = '-2'
FROM [SourceData],[WeekstoUpd]
where [WeekNum]>=[StartDate] and [WeekNum]<=[EndDate];
GO
/****** Update Absent Weeks ******/
UPDATE [SourceData]
SET [Abs_Status] = '-1'
FROM [SourceData]
WHERE [SourceData].[Abs_Status] = '1';
GO