你的行概念应该是要以某一列为排序得出来的概念。 包括2005中的ROW_NUMBER计算行的函数都必须要求ORDER BY 参数。
select tid=identity(int,1,1),* into # from tb order by id; select sum(price) as sumprice from # where tid between 3 and 5; drop table #sumprice ----------------------------------------------------- 123.8(所影响的行数为 1 行)
create table tb(id int,price float)
insert tb values(1,25)
insert tb values(3,32)
insert tb values(42,21)
insert tb values(46,50)
insert tb values(50,52.8)
insert tb values(51,60)
select sum(price) from tb a
where (select count(*) from tb where id<a.id) between 2 and 4/*
---
123.8
*/drop table tb
您好.非常感谢.
但我的ID 值是随机的.
有可能是如下值
ID Pice
1 25
60 32
142 21
46 50
10 52.8
51 60
包括2005中的ROW_NUMBER计算行的函数都必须要求ORDER BY 参数。
select tid=identity(int,1,1),* into # from tb order by id;
select sum(price) as sumprice from # where tid between 3 and 5;
drop table #sumprice
-----------------------------------------------------
123.8(所影响的行数为 1 行)