合并多个 sql 查询以获取不同时间段的数据
在 oracle 数据库中,您需要合并以下三个 sql 查询以从单表中提取不同时间段的数据:
select count(1) as flownum from ccform_debit_all where cf_acctime > to_char(sysdate, 'yyyy-mm-dd'); select count(1) as flownummonth from ccform_debit_all where cf_acctime > to_char(sysdate, 'yyyy-mm'); select count(1) as flownumtotal from ccform_debit_all where cf_acctime > to_char(sysdate, 'yyyy');
要合并这些查询,请使用 case 表达式,如下所示:
select count(case when to_char(cf_acctime, 'yyyy-MM-dd') > to_char(sysdate, 'yyyy-MM-dd') then 1 end) as flowNum, count(case when to_char(cf_acctime, 'yyyy-MM') > to_char(sysdate, 'yyyy-MM') then 1 end) as flowNumMonth, count(case when to_char(cf_acctime, 'yyyy') > to_char(sysdate, 'yyyy') then 1 end) as flowNumTotal from ccform_debit_all
这个合并查询将返回三列:flownum、flownummonth 和 flownumtotal,分别代表今天、本月和本年的流程数量。
以上就是如何使用单个 SQL 查询获取 Oracle 数据库中不同时间段的数据?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号