https://en.wikipedia.org/wiki/Simpson%27s_paradox
See in particular the Berkeley Gender Bias case if you don't want to hack the math apart.
The specific way you slice and dice data matters.