Reputation: 299
I have the below table.
TableA
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
How can I calculate the number of WorkDays in a month? I'm not sure where to start, so I don't have any work to show.
Expected output
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 I have the below but how can I add this to my query
SELECT COUNT(*),C.CALENDAR_MONTH FROM HUM.CALENDAR C WHERE 1=1 AND C.WORKDAY = 1 GROUP BY C.CALENDAR_MONTH
Upvotes: 1
Views: 121
Reputation: 1054
In much the same way as SUM you can also use COUNT if you want to limit it to just working days;
SELECT c.*,
COUNT(*) OVER(PARTITION BY calendarmonth ORDER BY calendarmonth) WDIM
FROM calendar
WHERE workday = 1
Depends how you want to use it I guess.
Upvotes: 0