In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `cte` ADD INDEX `cte_idx_employeeid_testid` (`EmployeeID`,`TestID`);
SELECT
cte.EmployeeID,
cte.TestID,
SUM(ISNULL(cte.Q1,
0) + ISNULL(cte.Q2,
0) + ISNULL(cte.Q3,
0)) / MIN(CASE
WHEN cte.Q1 IS NULL THEN 0.0
ELSE 1.0 END + CASE
WHEN cte.Q2 IS NULL THEN 0.0
ELSE 1.0 END + CASE
WHEN cte.Q3 IS NULL THEN 0.0
ELSE 1.0 END) AS AverageScore
FROM
cte
GROUP BY
cte.EmployeeID,
cte.TestID
ORDER BY
cte.TestID,
AverageScore