Theodore Roosevelt once famously stated that comparison this the thief of joy, and he's not wrong. Or, at least, comparison is a thief of joy. But it's not the only thief; and nor is it a negative thing all the time – that depends largely on what you're willing to do with it.
When comparisons are made just for the sake of comparing, they do tend to have no purpose. Someone else might have better grades then you, or a better car, or just a better life. In fact, these are easy things to compare; someone always has it better, and someone always has it worse. Noticing that doesn't necessarily do us any good, and if it makes us jealous of others, that's where the removal of joy comes in.
But sometimes, comparison can be used to make improvements. If you actually consider how to make things better, it can motivate you to push yourself. You can see a goal you would like to accomplish, and use the fact that you haven't yet as an encouragement to make a change and do so. As long as you're not using others' lives as excuses for why you "can't" or why you aren't as lucky, comparisons can serve to inspire positive changes.
You can also compare where you are now to where you've been in the past. Have you improved? That's a good way to inspire yourself to see how you can continue to do so in the future. Have you not improved as you might have liked? You can see what to avoid in the future to keep from going further down that path.
Comparison can certainly be used to bring negativity, but it can also be used for good. Half the battle is an awareness of what you do with the knowledge you take away from comparisons. If it does nothing other than make you envious, then it likely will serve to keep you from appreciating what you do have. But if you see the gap between where you are and where you want to be as a challenge to overcome, you can have the courage to work towards something you want. And that nudge to notice this can get you a long way.