❶ sql语句查询IP段
--先构建一个转换ip地址格式的函数 以‘.’为间隔按4段拆分 每段前端补0 然后截取3位
--可将‘1.1.166.0’转换为‘001001166000’
create function convertIP (@strIP varchar(20))
returns varchar(20)
as
begin
declare @str1 varchar(6),@str2 varchar(6),@str3 varchar(6),@str4 varchar(6),
@i int,@j int,@k int,@m int
set @i=1
set @j=1
set @k=1
set @m=1
while (@i<=len(@strIP))
begin
if (substring(@strIP,@i,1)='.')
begin
if @k=1 set @str1=substring(@strIP,@m,@j-1)
if @k=2 set @str2=substring(@strIP,@m,@j-1)
if @k=3 set @str3=substring(@strIP,@m,@j-1)
set @j=1
set @m=@i+1
set @k=@k+1
end
else
set @j=@j+1
set @i=@i+1
end
set @str4=substring(@strIP,@m,@j-1)
set @str1='000'+@str1
set @str1=substring(@str1,len(@str1)-2,3)
set @str2='000'+@str2
set @str2=substring(@str2,len(@str2)-2,3)
set @str3='000'+@str3
set @str3=substring(@str3,len(@str3)-2,3)
set @str4='000'+@str4
set @str4=substring(@str4,len(@str4)-2,3)
return @str1+@str2+@str3+@str4
end
--查询ip地址为标准格式 例如'201.125.12.203'
select address from IP where dbo.convertIP(IPstart)<=dbo.convert('201.125.12.203') and dbo.convertIP(IPend)>=dbo.convertIP('201.125.12.203')
❷ sql排序语句怎么写
select * from 你的表名字 order by user_lasttime asc
❸ sql中怎样为IP地址字段按大小排序在线等!
把ipAddr设置成主键试试。
❹ 这条sql语句这么写
PS:这个表里最起码也应该有个时间戳的字段吧,不然都是重复数据,hive下测试;
思路:先统计每个网址被不同IP访问的次数,然后以网站和ip进行分组,以次数降序排序,取小于等于3即可;(代码未取rank<=3,也要考虑次数一样的ip等);
code:
select t1.web,t1.ip,dense_rank() over(partition by t1.web,t1.ip order by t1.counts desc) as rank from (select web,ip,count(*) as `counts` from t group by web,ip)as t1
可以看下row_number()、dense_rank()、rank()的区别;
❺ Oracle 中 查询IP地址的SQL语句
下面是我在项目(使用的SqlMap)里一个SQL语句关于IP段查询的部分:
<isNotEmpty
prepend="AND"
property="startIP">
CONCAT(LPAD(SUBSTR(CLIENTIP,1,INSTR(CLIENTIP,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(CLIENTIP,INSTR(CLIENTIP,'.',1,1)+1,INSTR(CLIENTIP,'.',1,2)-INSTR(CLIENTIP,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(CLIENTIP,INSTR(CLIENTIP,'.',1,2)+1,INSTR(CLIENTIP,'.',1,3)-INSTR(CLIENTIP,'.',1,2)-1),3,'0'),
LPAD(SUBSTR(CLIENTIP,INSTR(CLIENTIP,'.',1,3)+1,LENGTH(CLIENTIP)),3,'0')
)
)
)
BETWEEN
CONCAT(LPAD(SUBSTR(#startIP#,1,INSTR(#startIP#,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(#startIP#,INSTR(#startIP#,'.',1,1)+1,INSTR(#startIP#,'.',1,2)-INSTR(#startIP#,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(#startIP#,INSTR(#startIP#,'.',1,2)+1,INSTR(#startIP#,'.',1,3)-INSTR(#startIP#,'.',1,2)-1),3,'0'),
LPAD(SUBSTR(#startIP#,INSTR(#startIP#,'.',1,3)+1,LENGTH(#startIP#)),3,'0')
)
)
)
AND
CONCAT(LPAD(SUBSTR(#endIP#,1,INSTR(#endIP#,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(#endIP#,INSTR(#endIP#,'.',1,1)+1,INSTR(#endIP#,'.',1,2)-INSTR(#endIP#,'.',1,1)-1),3,'0'),
CONCAT(LPAD(SUBSTR(#endIP#,INSTR(#endIP#,'.',1,2)+1,INSTR(#endIP#,'.',1,3)-INSTR(#endIP#,'.',1,2)-1),3,'0'),
LPAD(SUBSTR(#endIP#,INSTR(#endIP#,'.',1,3)+1,LENGTH(#endIP#)),3,'0')
)
)
)
</isNotEmpty>
❻ SQL IP地址排序
把ip换成数字再排序吧。换数字的办法要用程序去实现。
❼ 关于SQL排序的语句,求助
->
if
not
object_id(N'Tempdb..#T')
is
null
drop
table
#T
Go
Create
table
#T([ID]
int,[CategoryName]
nvarchar(8),[Parent]
nvarchar(5))
Insert
#T
select
1,N'简体版',N'0'
union
all
select
6,N'光电开关FPJ1',N'0.1'
union
all
select
7,N'光电开关DR',N'0.1'
union
all
select
8,N'磁性开关',N'0.1.7'
union
all
select
9,N'光电开关CR',N'0.1.7'
union
all
select
10,N'光电开关DR',N'0.1.7'
union
all
select
12,N'光电开关FPJ1',N'0.1.7'
union
all
select
13,N'光电开关CR',N'0.1'
union
all
select
14,N'磁性开关',N'0.1.7'
union
all
select
15,N'变位传感器',N'0.1'
Go
Select
a.categoryname
AS
lev1,
b.categoryname
as
lev2,
c.categoryname
as
lev3
from
#T
a
left
join
#T
b
on
rtrim(a.[Parent])+'.'+rtrim(a.[ID])=b.[Parent]
left
join
#T
c
on
rtrim(b.[Parent])+'.'+rtrim(b.[ID])=c.[Parent]
where
a.[CategoryName]=N'简体版'
❽ sql IP地址 排序
select *
from iptable
order by convert(numeric(20),replace(ip字段,'.',''))
❾ 通用SQL语句排序的方法
前十名:
select top 10 id,name,score from student order by score desc
第三名:
select top 1 * from (select top 3 * from [student] order by score desc) as tb1 order by score asc
注:使用 (top * asc )desc 这种方式在 rownumber 方法出来以前是最常用的sqlserver处理分页取值的方式
❿ 一个关于按照ip地址排序的sql语句。
order by replace(字段,".","")