Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Oracle系统日期_Sql_Oracle - Fatal编程技术网

Sql Oracle系统日期

Sql Oracle系统日期,sql,oracle,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-

我的问题需要帮助

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
我想要当天和上个月的结果以及每个月的总数谢谢


谢谢你

听起来你只是想要一个连续的总数

with monthly_data as (
  select count(item_number) cnt,
         trunc(creation_date, 'MON') as creation_date
   from EGP_SYSTEM_ITEMS_B 
  where organization_id='300000021164768'
  group by trunc(creation_date, 'MON')
)
select creation_date,
       cnt,
       sum(cnt) over (order by creation_date) running_cnt
  from monthly_data

您可以在汇总的同时进行汇总:

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);