VARCHAR top_level_domain(VARCHAR url)
Extract the top-level domain from a URL and return it. If the URL is invalid, return an empty string.
mysql [(none)]>select top_level_domain("www.baidu.com"); +-----------------------------------+ | top_level_domain('www.baidu.com') | +-----------------------------------+ | com | +-----------------------------------+ mysql [(none)]>select top_level_domain("www.google.com.cn"); +---------------------------------------+ | top_level_domain('www.google.com.cn') | +---------------------------------------+ | cn | +---------------------------------------+ mysql [(none)]>select top_level_domain("wwwwwwww"); +------------------------------+ | top_level_domain('wwwwwwww') | +------------------------------+ | | +------------------------------+
top_level_domain