Example 4 Find
$$
M=(x+1)(x+2) \cdots(x+n)
$$

the coefficient of $x^{n-2}$ in the expansion.
【Analysis】The coefficient of $x^{n-2}$ in $M$ is the sum of the products of any two numbers taken from $1,2, \cdots, n$, i.e.,
$$
\begin{aligned}
A= & 1 \times 2+1 \times 3+\cdots+1 \times n+ \\
& 2 \times 3+2 \times 4+\cdots+2 \times n+ \\
& \cdots+(n-1) n .
\end{aligned}
$$

The above expression is quite complex and difficult to handle. If we consider these sums as a whole and observe the characteristics of each part, we can think of the expansion of $\left(a_{1}+a_{2}+\cdots+a_{n}\right)^{2}$. It is not hard to find the following solution.
Solution From
$$
\begin{array}{l}
(1+2+\cdots+n)^{2} \\
=1^{2}+2^{2}+\cdots+n^{2}+2 A,
\end{array}
$$

we get $A=\frac{1}{2}\left[(1+2+\cdots+n)^{2}-\left(1^{2}+2^{2}+\cdots+n^{2}\right)\right]$
$$
=\frac{1}{24}(n-1) n(n+1)(3 n+2) \text {. }
$$