Four, (20 points) Given the quadratic function $y=x^{2}-x-2$ and the real number $a>-2$. Find:
(1) The minimum value of the function in $-2<x \leqslant a$;
(2) The minimum value of the function in $a \leqslant x \leqslant a+2$.
For the function $y=x^{2}-x-2$, the graph is shown in Figure 4.
(1) When $-2<a<\frac{1}{2}$,

$y_{\text {min }}=\left.y\right|_{x=a}=a^{2}-a-2$;
When $a \geqslant \frac{1}{2}$, $y_{\text {min }}=$
$$
\left.y\right|_{x=\frac{1}{2}}=-\frac{9}{4} \text {. }
$$
(2) When $-2<a$ and $a+2<\frac{1}{2}$, i.e., $-2<a<-\frac{3}{2}$,
$$
\begin{aligned}
y_{\text {min }} & =\left.y\right|_{x=a+2}=(a+2)^{2}-(a+2)-2 \\
& =a^{2}+3 a ;
\end{aligned}
$$

When $a<\frac{1}{2} \leqslant a+2$, i.e., $-\frac{3}{2} \leqslant a<\frac{1}{2}$,
$$
y_{\text {min }}=\left.y\right|_{x=\frac{1}{2}}=-\frac{9}{4} \text {; }
$$

When $a \geqslant \frac{1}{2}$, $y_{\text {min }}=\left.y\right|_{x=a}=a^{2}-a-2$.