Will be easy to give accurate query if you could give some sample output data which you require, you could also try to get your result as per given below example-
WITH CTE (rownum,QuizID,Username,SapCode,DivisionShortcut,Score,DateTimeComplete)
AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY U.Username,QuizID ORDER BY DateTimeComplete) rownum,
QuizID,U.Username,SapCode,DivisionShortcut,Score,DateTimeComplete FROM UserQuiz U
INNER JOIN employee E ON U.Username=E.Username
INNER JOIN Divisions D ON E.DivisionCode =D.SapCode
)
SELECT Username,DivisionShortcut,COUNT(Username) AS [Number of Participants] ,score FROM CTE
WHERE rownum=1 AND Score=100
GROUP BY Username,DivisionShortcut,score
3 People are following this question.