达梦数据库的分页查询

查询数据是在数据库中常用的操作,达梦数据库分页: 整合了sqlserver/mysql/oracle,可以有3种方法实现分页查询:top分页,limit分页,伪列分页。

top分页

查询订单表中前十条订单的记录
第一页

select top 10 * from vspace.i_order where order_id
not in(select top 0 order_id from vspace.i_order);

第二页

select top 10 * from vspace.i_order where order_id 
not in(select top 10 order_id from vspace.i_order);

第三页

select top 10 * from vspace.i_order where order_id 
not in(select top 20 order_id from vspace.i_order);

在这里插入图片描述

由上面总结可得出top分页的句式

select top 每页条数  要查询的内容 from 表 where id not in(
	selet top (当前页码 - 1)*每页条数 id from);

limit分页

每页显示10条

select * from vspace.i_order limit 0,10;
select * from vspace.i_order limit 10,10;
-- ...
--5页
select * from vspace.i_goods limit 40,10;

在这里插入图片描述

总结得出

select 要查的内容 fromlimit (当前页码 - 1)* 每页条数,每页条数;

伪列分页

i. rowid

Select rowid, 列名列表 from 表 where rowid between 起始编号 and 结束编号

ii. rownum

select t. 列名列表 from (
select rownum num, 列名列表 from 表名 where rownum < maxValue
) t where num > minValue
select rownum 编号,* from vspace.i_order where rownum <=10;

在这里插入图片描述

select * from (
	select rownum num,* from(
		select * from vspace.i_goods
	)t1 where rownum<=15
)t2 where t2.num>12;

--2页
select * from (
	select rownum num,* from (
		select o.order_id,g.goods_title,o.ammount,g.price 
		from vspace.i_order o,vspace.i_goods g
		where o.goods_id=g.goods_id order by o.order_id
	)t1 where rownum <=20
)t2 where t2.num >3;

高级查询

2.1多表联查

  1. 笛卡尔集查询
select 列名列表 from1,2;
  1. 内联接查询
select 列名列表 from1,2 where 两表关联列条件表达式;
select 列名列表 from1 inner join on 两表关联列条件表达式;
  1. 外联接查询
    a) 左外联接查询
select 列名列表 from1,2 where 两表关联列条件表达式;

b) 右外联接查询

select 列名列表 from1 inner join on 两表关联列条件表达式;

c) 全联接查询

select 列名列表 from1 left outer join 表 2 on 两表关联列条件表达式;

2.2 子查询
4. where 子句子查询: 将一个查询的结果作为另一个查询(更新)操作的条件

select 列名列表 from 表名 where 条件列 = | in | not in (
子查询
) [条件… 其他];
  1. from 子句子查询: 将一个查询的结果看做一张虚拟表提供给其他查询使用
 select 列名列表 from (
子查询
) 临时表名 [条件… 其他]; 
  1. select 子句子查询: 将一个查询的结果和其他查询的结果进行组合
 select 列名列表,(
子查询
) from 表名 [条件… 其他];
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐