order by… numbers? Help me sort ip addresses

后端 未结 2 906
清酒与你
清酒与你 2021-01-18 08:22

MySQL, Trying to get a list of ip addresses, in order.

this query

select ip from sn_192_168_0 

gives this

192.168.         


        
2条回答
  •  一个人的身影
    2021-01-18 08:56

    you can use

    SELECT ip FROM sn_192_168_0 ORDER BY LPAD(  ip, 16, 0 ) 
    

    the number 16 is the max length of the ip

提交回复
热议问题