these numbers aren't directly comparable.
The rent should be compared with the interest cost of the mortgage plus the capital cost of the deposit (which at minimum is the risk-free rate).
So if you paid 1/4th of your salary as rent, but the apartment costs 3x of your salary, this means you're paying 1/12th of the cost of the apartment as rent, aka, an 8% rental yield. This is an amazingly good yield - greater than the stock market expected yield (of 7%-ish). No wonder investors would want to buy.
The general consensus is that if the rental cost is greater than 5% of the property, you're better off paying the mortgage (and conversely, if the rental cost is less than 5%, then rent is cheaper, and invest the difference would yield more financial returns).
10 years ago my first real job was a research assistant position in Copenhagen. Housing was very reasonably priced, and I could buy an apartment in the suburbs with just 3 years of salary. I rented a nice place with 1/4 of my salary. It was great.
I then moved to Cambridge, and while the university is cool, real estate took most of my free income. It was a nightmare. More than 1/2 of my salary went to renting a small flat in the middle of nowhere. During the course of several years, my I had to move houses six times because landlords wanted more money, or because agents wanted to generate fees and the house actually sat empty without a tenant for pretty long.
Now, looking back at Copenhagen, and mostly anywhere else in the EU, is a nightmare. Salaries paid by the government have barely increased because inflation is said to have been really low. But buying or renting is easily 2.5x more money. If you live alone, it's hard to make both ends meet.