5. From 30 people with distinct ages, select two groups, the first with 12 people and the second with 15 people, such that the oldest person in the first group is younger than the youngest person in the second group. How many ways are there to select these groups?
5. 4060.

Assume the ages of these 30 people, from smallest to largest, are
$$
a_{1}<a_{2}<a_{3}<\cdots<a_{29}<a_{30} .
$$

Let the first group of 12 people be $a_{i_{1}}<a_{i_{2}}<\cdots<a_{i_{12}}$,
and the second group of 15 people be $a_{j_{1}}<a_{j_{2}}<\cdots<a_{j_{15}}$,
which are the ages of the two selected groups that meet the requirements.
Thus, $a_{i_{12}}<a_{j_{1}}$.
Therefore, this selection method corresponds one-to-one with
$$
a_{i_{1}}<a_{i_{2}}<\cdots<a_{i_{12}}<a_{j_{1}}<\cdots<a_{j_{15}}
$$

which is a 27-element subset of $\left\{a_{1}, a_{2}, \cdots, a_{30}\right\}$.
Hence, the number of selection methods is
$$
C_{30}^{27}=C_{30}^{3}=4060
$$