I have an attendance table in SQL Server 2012 named tblOrgHours. (attached) This is where I log all my attendance for different agencies in tracking how many hours each activity has been performed each day by different kids. The RegID in that same table is relational with the student information found in table tblOrgRegistrations. (attached) I need to create an sql query that will output the number of unique days of activity for each student during a specified time frame. Each day containing greater than 0 hours is considered a day of activity.
Here is the code I setup to get this data described above. Am I properly using the Distinct clause with ActivityDAte to attain what I described. Also, I am collecting other columns that concern me. I am not entirely familiar with the Group By clause, but am I using it correctly, once again, to get the desired output. Thus far, my output seems good, but I'd like experts to take a look at my query/syntax.
,Count(distinct H.ActivityDate) as [# of days]
from tblOrgHours H
inner join tblOrgRegistrations R on H.Regid = R.RegID
where H.[Hours] > 0
and h.fiscal = 2018
And h.ActivityDate >= '7/1/17' And h.ActivityDate <= '12/31/17'
group by H.Agency,h.SubGroup, r.LastName,r.FirstName,r.BirthDate,r.Grade,r.StudentID
Order by 1,4,5