As with the other answers, it is more important that you think about your own safety while you're doing your job. You can't help anybody if you're dead.
Prioritization of healing is situational. Observe your teammates and find out who is performing the game mode's ultimate goal most effectively in a given moment.
For example, on the main choke point blocking the path of Point A in Hanamura, Let's say there's an Orisa on your team that's on the front line, attracting a lot of attention from the enemy. It is vitally important that Orisa does not die, because this character is stopping the enemy from advancing and essentially keeping the rest of your team alive.
Let's say at the same time, you have a Genji on your team that's attempting to run through the opening in the wall and flank some enemies. This player does this with the inherent understanding that he's on his own. Danger is expected, and it would be much better for him to die alone instead of having him die along with his healer. When he needs healing, he should either find a health pack, or retreat into safe range of his healer. Any character that goes beyond the strategic front line that your team has established is strategically not worth risking your life to save.
When this Orisa character is at full health, prioritize healing to those around you who are essentially rendered useless with the amount of health that they have. A Symmetra on your team should take lower priority than a Soldier 76 or D.Va on your team at the same health. Also, consider each character's ability to passively regenerate HP. Symmetra and Zenyatta have the ability to regenerate their own HP (shield) by simply stepping out of danger for a moment. In these situations, those characters can be topped off when a convenient opportunity arises. Also consider each character's position in relation to a Health Pack on the map.
A good rule of thumb is to determine who has the highest amount of sustained enemy aggro as the game goes on. Who is the enemy prioritizing as they're pressing their attacks? Which player on your team attracts the most attention? Also, if your teammate is particularly effective at attracting attention, you might be less likely to be targeted.
In addition, Mercy more or less thrives when she's surrounded by her teammates. These friendlies are her lifeline if she gets flanked. If Mercy follows one teammate far away from the rest of her team, you only have one person that you can fly to in case of danger. She is also more vulnerable to characters like Tracer that prefer to gank solo, squishy targets whenever possible.
Mercy is also a character that doesn't stand out very well when in fights. When surrounded by friendlies, an enemy's first instinct is to attack those that would do them the most direct harm. Even if you pull out your pistol, you're much lower on the list of priority targets than most other characters.
Lastly, if you're unable to heal everybody as effectively as you should, maybe it's time for your team to pull back, regroup and find another spot to defend.