I don't know how or when it happened and the rim is aluminium. Could this be welded or do I need to replace the rim? Can I drive the car with this rim on?
It takes skill to make a GOOD weld in aluminum and it is very complicated ( expensive) to heat-treat an aluminum weld to bring the strength back to the same as the wheel , if possible at all. Routine welds in aluminum are low strength, not that some shop might say "sure we weld aluminum". It would be cheaper to buy a whole set of rims than to get a good weld.
Cast aluminum rims can normally be repaired. Forged aluminum is trickier. There are specialty shops that deal in repairing rims, go to one of them. This is not something you want to do yourself. If its a factory rim, consider buying a used replacement (much cheaper). See Craigslist
Welding is not an option when it comes to rims especially aluminium. If it was bent you may had a chance to fix it...
I would recommend replacing the rim with good quality ones.
It can be repaired, but I would seek a professional. Refer to this instructibles article to get an idea of the work involved. https://www.instructables.com/id/How-to-Repair-a-Cracked-Alloy-Wheel/