Group-by correlation vs All observations correlation
The name of the procedure you are looking for is


  Autocorrelation


This procedure looks a lot like the first you describe.

Answer fot this question in ResearchGate