MySQL SUBSTRING_INDEX()函数可以接受参数'count'的负值,在这种情况下,它从最终定界符的右边返回子字符串。
mysql> Select SUBSTRING_INDEX('www.google.com','.',-2); +------------------------------------------+ | SUBSTRING_INDEX('www.google.com','.',-2) | +------------------------------------------+ | google.com | +------------------------------------------+ 1 row in set (0.00 sec) mysql> Select SUBSTRING_INDEX('www.google.com','.',-1); +------------------------------------------+ | SUBSTRING_INDEX('www.google.com','.',-1) | +------------------------------------------+ | com | +------------------------------------------+ 1 row in set (0.00 sec)