利用MySql内置函数对IP进行排序
来源:互联网 发布:怎么查看淘宝违规商品 编辑:程序博客网 时间:2024/05/05 12:06
INET_ATON(expr)
Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4- or 8-byte addresses.
mysql> SELECT INET_ATON('209.207.224.40');
-> 3520061480
The generated number is always in network byte order. For the example just shown, the number is calculated as 209×2563 + 207×2562 + 224×256 + 40.
INET_ATON() also understands short-form IP addresses:
mysql> SELECT INET_ATON('127.0.0.1'), INET_ATON('127.1');
-> 2130706433, 2130706433
Note: When storing values generated by INET_ATON(), it is recommended that you use an INT UNSIGNED column. If you use a (signed) INT column, values corresponding to IP addresses for which the first octet is greater than 127 cannot be stored correctly. See Section 11.2, “Numeric Types”.
INET_NTOA(expr)
Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string.
mysql> SELECT INET_NTOA(3520061480);
-> '209.207.224.40'
以上是Mysql手册中的说明,下面用实例来说明如何用这些函数进行排序
假设ip是以字符串形式存储在表table_device的device_ip字段中,则以下这句可以返回以ip排序的结果
select device_ip from table_device order by inet_aton(device_ip)
结果:
192.168.0.1
192.168.0.51
92.168.0.111
92.168.0.223
Given the dotted-quad representation of a network address as a string, returns an integer that represents the numeric value of the address. Addresses may be 4- or 8-byte addresses.
mysql> SELECT INET_ATON('209.207.224.40');
-> 3520061480
The generated number is always in network byte order. For the example just shown, the number is calculated as 209×2563 + 207×2562 + 224×256 + 40.
INET_ATON() also understands short-form IP addresses:
mysql> SELECT INET_ATON('127.0.0.1'), INET_ATON('127.1');
-> 2130706433, 2130706433
Note: When storing values generated by INET_ATON(), it is recommended that you use an INT UNSIGNED column. If you use a (signed) INT column, values corresponding to IP addresses for which the first octet is greater than 127 cannot be stored correctly. See Section 11.2, “Numeric Types”.
INET_NTOA(expr)
Given a numeric network address (4 or 8 byte), returns the dotted-quad representation of the address as a string.
mysql> SELECT INET_NTOA(3520061480);
-> '209.207.224.40'
以上是Mysql手册中的说明,下面用实例来说明如何用这些函数进行排序
假设ip是以字符串形式存储在表table_device的device_ip字段中,则以下这句可以返回以ip排序的结果
select device_ip from table_device order by inet_aton(device_ip)
结果:
192.168.0.1
192.168.0.51
92.168.0.111
92.168.0.223
- 利用MySql内置函数对IP进行排序
- 利用MySql内置函数对IP进行排序
- javascript利用内置sort函数进行排序
- 利用正则表达对IP进行排序
- 利用函数指针对数组进行排序
- 利用函数指针对数组进行排序(选择排序实现)
- 利用mysql内置函数加锁
- 利用sort函数对数组进行排序【java】
- mysql中利用ceil函数对成绩进行分段统计
- Python 利用内置set函数对字符串和列表进行去重
- Python 利用内置set函数对字符串和列表进行去重
- 使用MySQL内置函数将IP地址字符串转为无符号整数进行存取
- 利用冒泡排序对数组进行排序
- 利用快速排序对单链表进行排序
- 如何对IP地址进行排序?
- 利用excel对记事进行时间排序
- 利用 NSSortDescriptor 对数组进行排序
- 利用ArrayList对Hashtable其进行排序
- java编译报类名是公共的错误
- [java]单例模式Singleton
- PL/SQL代码举例
- 年过完了,准备返京
- linux tar 命令
- 利用MySql内置函数对IP进行排序
- C# 创建验证码
- uml之聚合关系
- Oracle 11g R2 for Win7旗舰版(64位)的安装步骤
- svn的auth配置文件介绍
- [c#]BPlusTreePrototype - B+树的C#实现
- 某喜欢研究车的80后,驾驶经验59条
- 浅谈Linux服务器究竟设置多大交换分区合适
- ViewStub的实战开发