Why does it hurt that others have more than we do? Buddhism states that unsatisfactoriness (dukkah) is the cause of suffering and while I think this is truly insightful, it is also of course not a scientific observation. Evolutionary, since money signifies status we will suffer a loss in status when the relative gap to those that we compare ourselves to get a higher salary increase even if we also get a (smaller) increase. I think it's basically the same driving force that makes apes want to become the alpha male etc, so having a disposition that makes us strive for a climb on the social ladder has had a great adaptive value in the evolutionary process.
So that's some sort of explanation why this might be the case, but the more interesting question to me is how to counter this when we suffer in our own lives, because it's not always that the best thing for us is to invest even more in our careers in order to climb on the social ladder, and it might not always be possible. So how to deal with this?
Buddhism offers meditation as a part of the solution. In modern times, this has been developed into mindfulness practice which can arguably help with accepting issues such as this. I think that the basic idea here would be to train yourself to note any thoughts and feelings about this issue, and then letting them go so you're not affected by them as strongly.
Another solution comes from the stoicism of ancient Greece and Rome, which can be said to reconfigure our thoughts about such issues in order to achieve equanimity and tranquility. Personally, I've had some success in this regard with techniques from stoicism. Cognitive behavioural therapy (especially the cognitive part) can be said to be a modern adaptation of ancient stoicism, and also aims to change the way we think by questioning our underlying assumptions. I think this is where Ray Butterworth in the other answer is coming from.