zoukankan      html  css  js  c++  java
  • sql server分页

    select top 10 id,name,displayName from PM_User where name like '%yang%' order by id
    
    with tempPagination as(select ROW_NUMBER() OVER(ORDER BY  id) as RowNumber, 
    id,name,displayName from PM_User where name like '%yang%' ) 
    select * from tempPagination where RowNumber>10  and RowNumber<=20
    
    select * from 
    (
        select ROW_NUMBER()over(order by id desc) as rowNo,* from  PM_User where name like '%yang%'
    ) as t
    where rowNo between 0 and 200
    
    
     select * from 
        (select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from PM_User) as temp
    where rowNumber between 0 and 39
    
    
    SELECT COUNT(*) FROM (
            select id,name,displayName from PM_User where name like '%yang%'
    ) a
    public class Page {
    	public static void main(String[] args) {
    		int[] p = paging(38, 380, 0);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    		
    		p = paging(38, 380, 1);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    		
    		p = paging(38, 380, 2);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    		
    		p = paging(38, 380, 9);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    		
    		p = paging(38, 380, 10);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    		
    		p = paging(38, 380, 11);
    		System.out.println(p[0]);
    		System.out.println(p[1]);
    	}
    	//rowCountPerPage //每页多少条数据
    	//totalRows   //总条数
    	//pageCount  //总页数
    	//page  当前页码
    	//pageCount;//总页数
    	public static int[] paging(int rowCountPerPage, int totalRows, int page){
    		if (rowCountPerPage > 0) {//每页多少条数据
    			int pageCount=0;
    			if (page < 1) page = 1;
    			// Compute the begin and end row number //计算开始和结束行号
    			if (totalRows > rowCountPerPage) {
    				pageCount = (int) (totalRows + rowCountPerPage - 1) / rowCountPerPage;//总页数
    			} else if (totalRows <= rowCountPerPage) {
    				pageCount = 1;
    			}
    			if (page > pageCount) {
    				page = pageCount;
    			}
    			int iBegin = (page - 1) * rowCountPerPage + 1;//当前页开始index
    			int iEnd = iBegin + rowCountPerPage - 1;//当前页结束index
    			return new int[]{iBegin, iEnd};
    		}
    		return new int[]{0,0};
    	}
    }
    

      

  • 相关阅读:
    Windows Server 2012上PHP运行环境搭建的简易教程(Win08适用)
    Windows 8.1 系统ISO镜像下载或自Win8应用商店升级方法
    dojo布局(layout)
    dojo创建tree
    Postgres SQL学习笔记
    PostGIS ShapeFile 导入数据
    利用 PortableBasemapServer 发布地图服务
    Fortran 笔记
    ArcMap 操作笔记
    gdal编译C#开发版本
  • 原文地址:https://www.cnblogs.com/firstdream/p/7327606.html
Copyright © 2011-2022 走看看