您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

SqlServer 分页 ROW

2025/8/10 6:33:56发布19次查看
语法如下: select * from ( select *, row_number() over(order by a.createtime desc ) as rownumber from table_name as a ) as b where rownumber between 1 and 5 实例如下 select * from ( select row_number()over(order by dwhybh ) as rowno,* from
语法如下:
select * from ( 
select *, row_number() over(order by a.createtime desc ) as rownumber from table_name as a 
) as b 
where rownumber between 1 and 5 
实例如下
select * from 
(
select row_number()over(order by dwhybh ) as rowno,* from  c60dwyhxx
) as t
where rowno between 4 and 8
and t.dwjc like '%%'
and t.dwqc like '%%'
所用数据表为:
create table [dbo].[c60dwyhxx](
[dwhybh] [varchar](20) not null primary key ,
[dwjc] [varchar](20) not null,
[dwqc] [varchar](60) not null,
[dwlb] [int] not null,
[frdb] [dbo].[xm] null,
[frdbzsh] [varchar](30) null,
[lxr] [dbo].[xm] null,
[lxrmobile] [dbo].[mobile] null,
[qyemail] [varchar](50) null,
[dwlandline] [varchar](15) null,
[qywzdz] [varchar](40) null,
[yhmm] [char](32) null,
[djrq] [date] null,
[uniqueid] [int] not null,
[wtag] [int] null,
[strtag] [varchar](255) null,
[recversion] [bigint] null,
[yhid] [uniqueidentifier] null
)
第二部分:自己写的拼接有省市县三级拼接的sql语句
select row_number()over ( order by hybh) as rowno ,b.xm
,(
select xzqhwm from z21xzqh e where e.xzqh in (select substring(f.xzqh,0,3)+'0000' from c02yhjbxx  f 
left join z21xzqh d on f.xzqh=d.xzqh 
where f.xzqh=d.xzqh and f.yhid=a.yhid  )) as fir
,(
select xzqhwm from z21xzqh e where e.xzqh in (select substring(f.xzqh,0,5)+'00' from c02yhjbxx  f 
left join z21xzqh d on f.xzqh=d.xzqh 
where f.xzqh=d.xzqh and f.yhid=a.yhid  )) as sec
,(
select xzqhwm 
from c02yhjbxx  c 
left join z21xzqh d on c.xzqh=d.xzqh 
where c.xzqh=d.xzqh and c.yhid=a.yhid
) as thir
,b.xzqh,a.hybh,a.yhid,a.uniqueid 
from c70hygr a left join c02yhjbxx b on a.yhid=b.yhid
where 1=1
--select substring(xzqh,0,3)+'0000' from c02yhjbxx 
--select xzqh from c02yhjbxx
查询结果如下图所示
子查询里嵌套了in关键字。嘻嘻。效率应该不高。但是省的写代码拼接datatable了
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product