问题:将一个IP地址字段分解到列中,考虑下面列出的IP地址:
111.22.3.4
要得到如下所示的查询结果:
+-----+----+---+---+
| a | b | c | d |
+-----+----+---+---+
| 111 | 22 | 3 | 4 |
+-----+----+---+---+
解决方案:
select substring_index(substring_index(y.ip,'.',1),'.',-1) a,
substring_index(substring_index(y.ip,'.',2),'.',-1) b,
substring_index(substring_index(y.ip,'.',3),'.',-1) c,
substring_index(substring_index(y.ip,'.',4),'.',-1) d
from (select '111.22.3.4' as ip from t1) y;