Who are these scripts for? You need to troubleshoot performance problems with SQL Server, and you need to do it now. You don't have time to track down a bunch of DMVs, figure out Extended Events, ...
ROUND(AVG(Salary) OVER (PARTITION BY Department), 2) AS DeptAvgSalary, ROUND(Salary - AVG(Salary) OVER (PARTITION BY Department), 2) AS DiffFromAvg ...