You first need to determine the cause of the pain. The most common injury in some dogs is probably a torn cranial cruciate. This is comparable to the ACL ligament in people. If this is the case, there are surgeries that can repair it and the vet will offer steroids and anti-inflammatories to help with pain.
Another cause might be a luxating patella. In layman's terms this means wiggly kneecaps. If a dog has this condition, the knee will slip into and out of place. The dog might straighten the leg to flex it back in place.
I would also be concerned about a back or disc injury.
I hope this helps!
Unfortunately, you can't tell from the outside what the source of the pain may be.
Let me know if you have more questions about this.