分页查询,order by,where用法
2023-12-20 14:45:49
一、
//查询数据库ESS的Elog表格的ETime、Des列
//查询出的结果只显示这两列
SELECT E_LOG."ETime", E_LOG."Des", ROWNUM rn
FROM ESS."E_LOG"
二、
//分页查询ROWNUM 用法
//rn变量,行号,只查询返回结果表(1)的第0行到第30000行
SELECT * FROM (
SELECT E_LOG."ETime", E_LOG."Des", ROWNUM rn
FROM ESS."E_LOG"
) WHERE rn BETWEEN 0 AND 30000;
三、
//1、where用法
//只返回结果ETime列的DATE类型的值在这个区间的记录
//2、TO_DATE函数用法,可自定义时间,以及格式,只有年、有年月、有年月日、年月日时分秒,都可
实例1:
SELECT * FROM (
SELECT E_LOG."ETime", E_LOG."Des", ROWNUM rn
FROM ESS."E_LOG"
WHERE "ETime" BETWEEN TO_DATE('2022-11-30', 'YYYY-MM-DD') AND TO_DATE('2023-12-20', 'YYYY-MM-DD')
) WHERE rn BETWEEN 0 AND 30000;
实例2:
SELECT * FROM (
SELECT E_LOG."ETime", E_LOG."Des", E_LOG."StnName",ROWNUM rn
FROM ESS."E_LOG"
WHERE "ETime" BETWEEN TO_DATE('2022-11-30 09:44:23', 'yyyy-mm-dd HH24:mi:ss') AND TO_DATE('2023-12-20 13:39:00', 'yyyy-mm-dd HH24:mi:ss')
) WHERE rn BETWEEN 0 AND 30000;
SELECT * FROM (
SELECT E_LOG."ETime", E_LOG."Des", ROWNUM rn
FROM ESS."E_LOG"
WHERE "ETime" BETWEEN TO_DATE('2022-11-30 09:44:23', 'yyyy-mm-dd HH24:mi:ss') AND TO_DATE('2023-12-20 13:39:00', 'yyyy-mm-dd HH24:mi:ss')
ORDER BY "ETime"
) WHERE rn BETWEEN 0 AND 30000;
SELECT * FROM (
SELECT E_LOG."ETime", E_LOG."Des", ROWNUM rn
FROM ESS."E_LOG"
WHERE "ETime" BETWEEN TO_DATE('2022-11-30', 'YYYY-MM-DD') AND TO_DATE('2023-12-20', 'YYYY-MM-DD')
ORDER BY "ETime"
) WHERE rn BETWEEN 0 AND 30000;
四、
//分页查询,另一种方法OFFSET n从第n行开始
//fetch next rows only只查从第几行开始的rows行记录
SELECT COUNT(*) FROM ESS.E_LOG;
SELECT E_LOG."ETime", E_LOG."ELevel"
FROM ESS.E_LOG
WHERE "Type"=160
OFFSET 0 ROWS
FETCH NEXT 30000 ROWS ONLY;
文章来源:https://blog.csdn.net/m0_46104251/article/details/135106390
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!