Algebra with finite summations Let $X$ and $Y$ be two random variables that can take on $n$ values.

How do I show: $$\frac {n\sum X_{i}Y_{i}-\sum X_{i} \sum Y_{i}}{n\sum X_{i}^2-(\sum X_{i})^2}=\frac{\sum (X_{i}-\bar X)(Y_{i}-\bar Y)}{\sum (X_{i}-\bar X)^2}$$

With $\bar X$ and $\bar Y$ the means of the random variables $X$ and $Y$ respectively.
Using the formulas that Daniel McLaury indicated:

$$\frac{E(XY)-E(X)E(Y)}{E(X^2)-E(X)E(X)}=\frac{\sum X_{i}Y_{i}P(X_{i},Y_{i})-\sum X_{i}f(X_{i})\sum Y_{i}g(Y_{i})}{\sum X_{i}^2 f(X_{i})-\sum X_{i}f(X_{i})\sum X_{i}f(X_{i})}$$

With $f(X)$ the PDF of $X$ and $g(X)$ the PDF of $Y$.
Since the equation only holds for uniformly distributed random variables:

$$=\frac {\frac{1}{n}\sum X_{i}Y_{i}-\frac{1}{n^2}\sum X_{i}\sum Y_{i}}{\frac{1}{n}\sum X_{i}^2-\frac{1}{n^2}\sum X_{i}\sum X_{i}}$$

We multiply numerator and denominator by $n^2$ to get the given equation:

$$=\frac {n\sum X_{i}Y_{i}-\sum X_{i} \sum Y_{i}}{n\sum X_{i}^2-(\sum X_{i})^2}$$

$$\therefore \frac{E(XY)-E(X)E(Y)}{E(X^2)-E(X)E(X)}=\frac {n\sum X_{i}Y_{i}-\sum X_{i} \sum Y_{i}}{n\sum X_{i}^2-(\sum X_{i})^2}=\frac {Cov(X,Y)}{Var(X)}=\frac {\sum (X_{i}-\bar X)(Y_{i}-\bar Y) P(X_{i},Y_{i})}{\sum (X_{i}-\bar X)^2f(X_{i})}=\frac {\frac{1}{n}\sum (X_{i}-\bar X)(Y_{i}-\bar Y)}{\frac{1}{n}\sum (X_{i}-\bar X)^2}=\frac{\sum (X_{i}-\bar X)(Y_{i}-\bar Y)}{\sum (X_{i}-\bar X)^2}$$

Edit: as far as I know, $E(XY)=\sum \sum X_{i}Y_{j}P(X_{i},Y_{j})$, so either I'm missing something or the study book put a mistaken $i$ subscript for Y in the left-hand side of the numerator.

Edit 2: For every $X_{i}$ there is a unique $Y_{i}$ associated. The variables are dependent, we cannot include cases $X_{i}Y_{j}$ where $i\ne j$ (we could, but the associated intersection probability would be 0 for all cases).
Up to some power of $n$, the numerators on each side are the covariance of $X$ and $Y$ and the denominators on both sides are the variance of $X$.  The equivalence is a result of the famous formula
$$Var[X] = \mathbb{E}[X^2] - \mathbb{E}[X]^2$$
and the analogous result for variances.

This is something you want to be able to spot in general; it's maybe the most useful formula in all of statistics and probability.