慕标琳琳
SELECT A.CName AS 班级名称, A.GNum AS 年级,
(SELECT COUNT(*) FROM [dbo].[LeaveInfo] AS B
WHERE B.CName = A.CName AND B.GNum = A.GNum AND B.[Statu] = 1
AND B.BeginDate >= DATEADD(DD,DATEDIFF(DD,0,GETDATE()),0)
AND B.EndDate < DATEADD(DD,DATEDIFF(DD,0,GETDATE()),1)) AS 今日请假,
(SELECT COUNT(*) FROM [dbo].[LeaveInfo] AS B
WHERE B.CName = A.CName AND B.GNum = A.GNum AND B.[Statu] = 1
AND B.BeginDate >= DATEADD(DD,DATEDIFF(DD,0,GETDATE()),-1)
AND B.EndDate < DATEADD(DD,DATEDIFF(DD,0,GETDATE()),0)) AS 昨日请假,
(SELECT COUNT(*) FROM [dbo].[LeaveInfo] AS B
WHERE B.CName = A.CName AND B.GNum = A.GNum AND B.[Statu] = 1
AND B.BeginDate >= DATEADD(WK,DATEDIFF(WK,0,GETDATE()),0)
AND B.EndDate < DATEADD(WK,DATEDIFF(WK,0,GETDATE()),7)) AS 本周请假,
(SELECT COUNT(*) FROM [dbo].[LeaveInfo] AS B
WHERE B.CName = A.CName AND B.GNum = A.GNum AND B.[Statu] = 1
AND B.BeginDate >= DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)
AND B.EndDate < DATEADD(MM,DATEDIFF(MM,0,GETDATE()) + 1,0)) AS 本月请假FROM [dbo].[LeaveInfo] AS A
GROUP BY A.CName, A.GNum