我有下表。
表A
DaysInMonth CalDate CalendarMonth MonthEndInd CalDateMonth WorkDay HolidayInd
31 3/26/2018 MAR 2018 N 3/31/2018 1 N
31 3/25/2018 MAR 2018 N 3/31/2018 0 N
如何计算一个月内的工作日数? 我不知道从哪里开始,所以我没有任何工作要展示。
预期输出
DaysInMonth CalDate CalendarMonth MonthEndInd CalDateMonth WorkDay HolidayInd WorkDaysInMonth
31 3/26/2018 MAR 2018 N 3/31/2018 1 N
31 3/25/2018 MAR 2018 N 3/31/2018 0 N
SQL我有以下内容,但如何将其添加到我的查询
SELECT COUNT(*),C.CALENDAR_MONTH FROM HUM.CALENDAR C WHERE 1=1 AND C.WORKDAY = 1 GROUP BY C.CALENDAR_MONTH
答案 0 :(得分:1)
您可以使用分析功能:
SELECT c.*,
SUM( WorkDay ) OVER ( PARTITION BY CalendarMonth ) AS WorkDaysInMonth
FROM Calendar C;
答案 1 :(得分:0)
与SUM大致相同,如果您想将其限制为工作日,也可以使用COUNT;
SELECT c.*,
COUNT(*) OVER(PARTITION BY calendarmonth ORDER BY calendarmonth) WDIM
FROM calendar
WHERE workday = 1
取决于你想要如何使用它。