Tsql 周到日期数据过滤器

Tsql 周到日期数据过滤器,tsql,Tsql,提供了以下数据: 学生障碍([StudentID]、[Date缺席]、[ReasonCode]) 学生详细信息([StudentID]、[GivenNames]、[姓氏]、[YearLevel]、[House]) 问题:我正在尝试为一位客户生成一份报告,该客户希望看到在特定时期缺席的前3名以上学生。这段时间可以是从上周到上月到去年的任何时间段。我目前的报告给了他们: Student's Name (concatenation of GivenNames and Surname) Unexplai

提供了以下数据:

学生障碍([StudentID]、[Date缺席]、[ReasonCode])

学生详细信息([StudentID]、[GivenNames]、[姓氏]、[YearLevel]、[House])

问题:我正在尝试为一位客户生成一份报告,该客户希望看到在特定时期缺席的前3名以上学生。这段时间可以是从上周到上月到去年的任何时间段。我目前的报告给了他们:

Student's Name (concatenation of GivenNames and Surname)
Unexplained (Number of Unexplained Absences during that particular period)
All Year to Date (The count of ALL the different types of Absence reasons for YTD)
Year Level (The student's Year Level)
麻烦的是,他们现在也想要一个“本周截止日期”专栏,但只是因为原因不明的缺席。这意味着他们希望看到每个学生从该周的周一开始缺课的次数


有什么建议吗?

这是我的第一个想法。本周前三名学生缺课

DECLARE @StartDate DateTime,
        @EndDate DateTime

SELECT @StartDate=DATEADD(ww, DATEDIFF(ww,0,GETDATE()), 0), @EndDate=GetDate()

SELECT D.*
FROM StudentDetails D
INNER JOIN 
(SELECT TOP 3 StudentID
FROM StudentAbsences
WHERE DateAbsent Between @StartDate and @EndDate
GROUP BY StudentID, CONVERT (nvarchar(10),DateAbsent, 102)
ORDER BY  COUNT(CONVERT (nvarchar(10),DateAbsent, 102)) DESC) A ON A.StudentID = D.StudentID 

这是我的第一张照片。本周前三名学生缺课

DECLARE @StartDate DateTime,
        @EndDate DateTime

SELECT @StartDate=DATEADD(ww, DATEDIFF(ww,0,GETDATE()), 0), @EndDate=GetDate()

SELECT D.*
FROM StudentDetails D
INNER JOIN 
(SELECT TOP 3 StudentID
FROM StudentAbsences
WHERE DateAbsent Between @StartDate and @EndDate
GROUP BY StudentID, CONVERT (nvarchar(10),DateAbsent, 102)
ORDER BY  COUNT(CONVERT (nvarchar(10),DateAbsent, 102)) DESC) A ON A.StudentID = D.StudentID 
试试看

试试看