SQL Server, Having Clause, Where, Aggregate Functions -
in problem trying solve, there performance values table:
staff performanceid date percentage -------------------------------------------------- staffname1 1 2/15/2016 95 staffname1 2 2/15/2016 95 staffname1 1 2/22/2016 100 ... staffname2 1 2/15/2016 100 staffname2 2 2/15/2016 100 staffname2 1 2/22/2016 100
and sql statement follows:
select top (10) tbl_staff.staffname, round(avg(tbl_staffperformancesvalues.percentage), 0) averagerating tbl_staff inner join tbl_academictermsstaff on tbl_staff.staffid = tbl_academictermsstaff.staffid inner join tbl_staffperformancesvalues on tbl_academictermsstaff.staffid = tbl_staffperformancesvalues.staffid (tbl_staffperformancesvalues.date >= @datefrom) , (tbl_academictermsstaff.schoolcode = @schoolcode) , (tbl_academictermsstaff.academictermid = @academictermid) group tbl_staff.staffname order averagerating desc, tbl_staff.staffname
what trying is, given date, instance 02-22-2016, want calculate average performance each staff member.
the code above gives me average without considering date filter.
thank you.
apart join conditions , table names looks quite complex, 1 simple question, if want results particular date why need of having
where tbl_staffperformancesvalues.date >= @datefrom
as said query displaying average results not date instance. change above line where tbl_staffperformancesvalues.date = @datefrom
.
correct me if wrong.
Comments
Post a Comment