Here is a query that does the calculation in the formula:
select sum((first_score - avg_first_score)*(second_score - avg_second_score)) /
(sqrt(sum(pow((first_score - avg_first_score), 2)))*
sqrt(sum(pow((second_score - avg_second_score), 2)))
) as r
from connections c cross join
(select avg(first_score) as avg_first_score, avg(second_score) as avg_second_score
from connections
) const;
There are numerous issues with your attempt. This precalculates the average values for the two scores. It then applies the formula pretty much as written.