日期:2014-05-17 浏览次数:21233 次
insert table AnalyzeJQ
(
date,
num,
amt,
)
select "20120601",
count(distinct num),
sum(amt)
from t_log
where (date >= "20120601" and date <= "20120630")
select c_date,
sum(c_count) over(partition by substr(c_date,1,6) --按月分组
order by c_date) as data_count
from
(select c_date,
count(*) as c_count)
from tab
group by c_date)
------解决方案--------------------
with t1 as
(
select date'2012-06-01' c1,'a' c2,100 c3 from dual
union all
select date'2012-06-01' c1,'a' c2,200 c3 from dual
union all
select date'2012-06-10' c1,'b' c2,300 c3 from dual
union all
select date'2012-06-10' c1,'c' c2,400 c3 from dual
union all
select date'2012-06-20' c1,'c' c2,500 c3 from dual
union all
select date'2012-06-25' c1,'c' c2,600 c3 from dual
union all
select date'2012-06-30' c1,'c' c2,700 c3 from dual
union all
select date'2012-06-30' c1,'d' c2,700 c3 from dual
)
select c1,
count(distinct c2) c2,
(select sum(c3) from t1 b where b.c1 <= a.c1) c3
from t1 a
group by c1
c1 c2 c3
------------------------------------------
1 2012/6/1 1 300
2 2012/6/10 2 1000
3 2012/6/20 1 1500
4 2012/6/25 1 2100
5 2012/6/30 2 3500