I've seen a sentence like
Ich habe Deutsch an der Schule gelernt.
Ich habe Deutsch in der Schule gelernt.
Why is the preposition "an" used? Does it have something to do with the past?
Well, to me (as a Bavarian) both seems to be correct, even
specifies the act of learing or teaching at a school to me
specifies the location or the act of learning or teaching
You can't say 'an' in this case.
Again, this is my personal opinion.
As a German I actually did not hear "an der Schule gelernt" and think it's incorrect in this context. "in der Schule" is correct.
"an" is only correct in the right context, like "An meiner Schule war es immer nett" (It was always nice at our school), referencing to the building or place rather than school as an institution or part of your life. You can also say "an" if your referencing to a specific school, like "I haben Deutsch an der Albert Einstein High School gelernt"
You can say "Ich habe Deutsch an der Schule gelernt", but only if you talk about specific school: