sqlserver 使用 ROW_NUMBER() OVER(order by xxx)进行分页查询_百度...
发布网友
发布时间:2022-04-25 12:44
我来回答
共1个回答
热心网友
时间:2022-04-11 16:22
只能做一个嵌套,按照你的,我建了几个表和查询,你看看,符合你要求不
建表
create table a (id int,
name varchar(10));
create table b (
name varchar(10),
qty int);
插入数据
insert into a values (1,'张三')
insert into a values (2,'李四')
insert into a values (3,'王五')
insert into a values (4,'赵六')
insert into a values (5,'孙七')
insert into b values ('张三',100)
insert into b values ('张三',200)
insert into b values ('李四',500)
insert into b values ('王五',100)
insert into b values ('王五',200)
insert into b values ('王五',500)
运行语句
select t.name,t.qty,row_number() over (order by t.qty)
from
(select a.name,sum(b.qty) qty
from a left join b on a.name=b.name group by a.name) t
结果截图