What is the best way to paginate results in SQL Server

前端 未结 19 2496
我寻月下人不归
我寻月下人不归 2020-11-22 01:36

What is the best way (performance wise) to paginate results in SQL Server 2000, 2005, 2008, 2012 if you also want to get the total number of results (before paginating)?

19条回答
  •  伪装坚强ぢ
    2020-11-22 02:00

       CREATE view vw_sppb_part_listsource as 
        select row_number() over (partition by sppb_part.init_id order by sppb_part.sppb_part_id asc ) as idx, * from (
          select 
              part.SPPB_PART_ID
              , 0 as is_rev
              , part.part_number 
              , part.init_id 
          from t_sppb_init_part part 
          left join t_sppb_init_partrev prev on ( part.SPPB_PART_ID = prev.SPPB_PART_ID )
          where prev.SPPB_PART_ID is null 
          union 
          select 
              part.SPPB_PART_ID
              , 1 as is_rev
              , prev.part_number 
              , part.init_id 
          from t_sppb_init_part part 
          inner join t_sppb_init_partrev prev on ( part.SPPB_PART_ID = prev.SPPB_PART_ID )
        ) sppb_part
    

    will restart idx when it comes to different init_id

提交回复
热议问题