新建数据库表(track):
trackid(主键自增(1,1)) ,CKId(bigint) , CKm (float型),KKm(float型)
执行查询:
1:select *,square(CKm+kkm)*square(KKm/CKm) as num into # from track order by num asc
select * from # a where not exists(select 1 from # where CKid=a.CKid and num<a.num) order by num
2: 然后对查询出来的这些数据进行分页?
现在把1做存储过程了,如果要进行分页, 该怎么写?
坐等高手。
------解决方案--------------------
GOOGLE. 分页存储过程...
------解决方案--------------------
- SQL code
关于分页的存过(来自CSDN)=========================================================================*/CREATE PROCEDURE [dbo].[Basic_Pagination2005]@tblName nvarchar(200), --表名@fidlelist nvarchar(1000), --要查询字段@fldName nvarchar(100), --排序字段@PageSize int, --页尺寸@PageIndex int, --页码@IsReCount bit , -- 返回记录总数, 非 0 值则返回@OrderType bit, -- 设置排序类型, 非 0 值则降序@strWhere nvarchar(1000) --查询条件ASdeclare @sqlstr nvarchar(4000),@tmpwhere nvarchar(4000),@tmporder nvarchar(100)BEGINif @OrderType != 0beginset @tmporder = @fldName +' desc 'endelsebegin set @tmporder = @fldName +' asc 'endset @tmpwhere='';if(@strWhere!='')beginset @tmpwhere=' where [email protected];endset @sqlstr=N'select * from(select [email protected]+', ROW_NUMBER() OVER(orderby [email protected]+') as row from [email protected][email protected]+') tmp where row between '+cast(((@PageIndex-1)[email protected]+1) as nvarchar)+' and '+cast(@[email protected] as nvarchar); exec sp_executesql @sqlstrif @IsReCount != 0beginset @sqlstr=N'select count(*) as Total from '+ @[email protected]exec sp_executesql @sqlstr endEND--返回第三页EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,3,200,1,'GRADE IS NOT NULL' --返回第10页EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,10,200,1,'GRADE IS NOT NULL' DROP PROC [Basic_Pagination2005]
------解决方案--------------------
row_number over(order by)
------解决方案--------------------
关于分页的存过(来自CSDN)
=========================================================================*/
CREATE PROCEDURE [dbo].[Basic_Pagination2005]
@tblName nvarchar(200), --表名
@fidlelist nvarchar(1000), --要查询字段
@fldName nvarchar(100), --排序字段
@PageSize int, --页尺寸
@PageIndex int, --页码
@IsReCount bit , -- 返回记录总数, 非 0 值则返回
@OrderType bit, -- 设置排序类型, 非 0 值则降序
@strWhere nvarchar(1000) --查询条件
AS
declare @sqlstr nvarchar(4000),
@tmpwhere nvarchar(4000),@tmporder nvarchar(100)
BEGIN
if @OrderType != 0
begin
set @tmporder = @fldName +' desc '
end
else
begin
set @tmporder = @fldName +' asc '
end
set @tmpwhere='';
if(@strWhere!='')
begin
set @tmpwhere=' where [email protected];
end
set @sqlstr=N'select * from
(select [email protected]+', ROW_NUMBER() OVER(order
by [email protected]+') as row from [email protected][email protected]+')
tmp where row between '+cast
(((@PageIndex-1)[email protected]+1) as nvarchar)+' and '+cast
(@[email protected] as nvarchar);
exec sp_executesql @sqlstr
if @IsReCount != 0
begin
set @sqlstr=N'select count(*) as Total from '+ @[email protected]
exec sp_executesql @sqlstr
end
END
--返回第三页
EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,3,200,1,'GRADE IS NOT NULL'
--返回第10页
EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,10,200,1,'GRADE IS NOT NULL'
DROP PROC [Basic_Pagination2005]
------解决方案--------------------