zoukankan      html  css  js  c++  java
  • 四种数据库分页查询的编写

    mysql : 

    select * from 表名 order by 表列 desc limit 30,40;

    sqlserver:

    第一种写法: 使用开窗函数

    select * from 
         (select row_number() over(order by empno) as rownum, * from emp) as a
      where a.rownum >=30 and a.rownum <=40

    第二种写法:使用子查询

    select top 10 * from emp 
      where empno not in 
     (select top 30 empno from emp order by empno desc)
     order by empno desc 

    oracle:

    第一种写法:使用开窗函数(类似sqlserver  )

    注意: 1)oracle 给表起别名不能加 as 。

        2)rownum在oracle 中是关键字。

    select * from 
         (select row_number() over(order by empno) as rownum2, * from emp) as a
      where a.rownum2 >=30 and a.rownum2 <=40

    第二种写法: 使用oracle自带的伪列rownum 

    select * from
     (select rownum ,*  from emp  order by empno desc  )  a  
     where a.rownum between 30 and 40

    db2:

    第一种写法:使用开窗函数

    select * from 
     (select row_number() over(order by empno) as rownum, * from emp) as a
    
      where a.rownum >=30 and a.rownum <=40

    第二种写法:使用子查询

    select * from emp
     where empno not in
    (select * from emp order by empno   fetch frist 30 rows only) 
    order by empno   fetch frist 10 rows only
  • 相关阅读:
    解决uniapp中app.vue的onlaunch不能跳转页面问题
    参数校验注解,备用
    码云推送项目总是没有权限
    一句话解释回调函数
    动态管理
    转:用jupyter notebook打开指定目录下的.ipynb文件
    gcn变体
    图4
    节点分类
    图3
  • 原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_sql_001.html
Copyright © 2011-2022 走看看