达梦数据库的分页查询
达梦数据库的分页查询达梦数据库的分页查询top分页limit分页伪列分页高级查询达梦数据库的分页查询查询数据是在数据库中常用的操作,达梦数据库分页: 整合了sqlserver/mysql/oracle,可以有3种方法实现分页查询:top分页,limit分页,伪列分页。top分页查询订单表中前十条订单的记录第一页select top 10 * from vspace.i_order where or
·
达梦数据库的分页查询
达梦数据库的分页查询
查询数据是在数据库中常用的操作,达梦数据库分页: 整合了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 要查的内容 from 表 limit (当前页码 - 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多表联查
- 笛卡尔集查询
select 列名列表 from 表 1,表 2;
- 内联接查询
select 列名列表 from 表 1,表 2 where 两表关联列条件表达式;
select 列名列表 from 表 1 inner join on 两表关联列条件表达式;
- 外联接查询
a) 左外联接查询
select 列名列表 from 表 1,表 2 where 两表关联列条件表达式;
b) 右外联接查询
select 列名列表 from 表 1 inner join on 两表关联列条件表达式;
c) 全联接查询
select 列名列表 from 表 1 left outer join 表 2 on 两表关联列条件表达式;
2.2 子查询
4. where 子句子查询: 将一个查询的结果作为另一个查询(更新)操作的条件
select 列名列表 from 表名 where 条件列 = | in | not in (
子查询
) [条件… 其他];
- from 子句子查询: 将一个查询的结果看做一张虚拟表提供给其他查询使用
select 列名列表 from (
子查询
) 临时表名 [条件… 其他];
- select 子句子查询: 将一个查询的结果和其他查询的结果进行组合
select 列名列表,(
子查询
) from 表名 [条件… 其他];
更多推荐
已为社区贡献1条内容
所有评论(0)