sql - Sql Oracle 系统日期
问题描述
我的查询需要帮助
select count(item_number),
trunc(creation_date, 'MON') as creation_date
from EGP_SYSTEM_ITEMS_B
where organization_id='300000021164768'
group by trunc(creation_date, 'MON')
输出是
1-3-2021: 200
1-4-2021: 150
1-5-2021: 300
我想要这样的输出:
1-4-2021: the sum of the previous count will be 350
1-5-2021: will be 650
我想要当天和上个月的结果以及每个月的计数总和谢谢
谢谢你
解决方案
您可以与聚合一起进行汇总:
select trunc(creation_date, 'MON') as creation_date,
count(*) as this_month_cnt,
sum(count(*)) over (partition by organization_id, order by trunc(creation_date, 'MON')) as running_cnt
from EGP_SYSTEM_ITEMS_B
where organization_id = '300000021164768'
group by trunc(creation_date, 'MON')
order by min(creation_date);
推荐阅读
- sql - What is the difference between LIKE '[A-D]%' ; and BETWEEN 'A' AND 'D' ; in SQL Server
- angular - 在 Angular 6 中重用组件 html
- vba - 如何创建一个内置用户表单的excel
- python - 如何在 Python 的哈希表中实现动态哈希?
- java - 无法通过套接字在android中的图像视图上显示图像
- spring-boot - MockMVC 测试如何验证答案
- android - RecyclerView 与 cursor Adapter 的实现
- r - R根据多行删除计数最少的行
- java - 抛出新异常并立即捕获它以避免代码重复。可能的?
- react-native - navigator.geolocation.getCurrentPosition 没有在带有 React Native 的 iOS 模拟器中触发