-- 累加统计 ddi_install_manage 表每个月已切换的数据数据量
SELECT a.month as Name, SUM(b.total) AS Value
FROM (
select ym AS month, SUM(sum) AS total
FROM (
select to_char(to_timestamp(remarks2,'yyyy-MM')+'1 month','yyyy-MM') as ym,count(*) as sum
from ddi_install_manage
where 1=1 and remarks1 ='已切换' and remarks2 is not null AND statecode =0
group by to_char(to_timestamp(remarks2,'yyyy-MM')+'1 month','yyyy-MM') order by ym desc
) ptuser
GROUP BY month
) a
JOIN (
SELECT ym AS month, SUM(sum) AS total
FROM (
select to_char(to_timestamp(remarks2,'yyyy-MM')+'1 month','yyyy-MM') as ym,count(*) as sum
from ddi_install_manage
where 1=1 and remarks1 ='已切换' and remarks2 is not null AND statecode =0
group by to_char(to_timestamp(remarks2,'yyyy-MM')+'1 month','yyy
sql累加统计每个月的数量
最新推荐文章于 2024-05-06 16:21:33 发布