select ip,SUBSTRING_INDEX(ip, '.', 1) as ip1,SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 2), '.', -1) as ip2,SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 3), '.', -1) as ip3,SUBSTRING_INDEX(ip, '.', -1) as ip4 from a
where SUBSTRING_INDEX(ip, '.', 1)+0>=0
and SUBSTRING_INDEX(ip, '.', 1)+0<255 and SUBSTRING_INDEX(ip, '.', 1)<>'' and SUBSTRING_INDEX(ip, '.', 1) REGEXP '[^0-9.]' =0
and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 2), '.', -1)+0>=0 and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 2), '.', -1)+0<255 and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 2), '.', -1)<>'' and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 2), '.', -1) REGEXP '[^0-9.]' =0
and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 3), '.', -1)+0>=0 and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 3), '.', -1)+0<255 and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 3), '.', -1)<>'' and SUBSTRING_INDEX(SUBSTRING_INDEX(IP, '.', 3), '.', -1) REGEXP '[^0-9.]' =0
and SUBSTRING_INDEX(ip, '.', -1)+0>=0 and SUBSTRING_INDEX(ip, '.', -1)+0<255 and SUBSTRING_INDEX(ip, '.', -1)<>'' and SUBSTRING_INDEX(ip, '.', -1) REGEXP '[^0-9.]' =0
and LENGTH(IP)-LENGTH(REPLACE(IP,'.',''))=3
新建表a
字段为ip一个