What could be the cause of erectile dysfunction during sex?

https://www.icliniq.com/qa/masturbation/why-am-i-able-to-maintain-erection-during-masturbation-but-not-sex

I am able to maintain erection during masturbation but not sex. Why?