17,377
社区成员
发帖
与我相关
我的任务
分享
select sum(ttmoney), t.pk_customer, add_months( to_date(min(t.ordertime),'yyyy-MM-dd HH24:mi:ss'), -1)
from table t
where t.ordertime between to_char( add_months(sysdate, -1),'yyyy-mm-dd hh24:mi:ss')
and (select min( t.ordertime) from table )
group by t.pk_customer
select sum(ttmoney), t.pk_customer, add_months( to_date(min(t.ordertime),'yyyy-MM-dd HH24:mi:ss'), -1)
from table t ,(select min( t.ordertime) D from table) A
where t.ordertime between to_char(add_months( to_date(A.D,'yyyy-MM-dd HH24:mi:ss'), -1),'yyyy-MM-dd HH24:mi:ss') and A.D
group by t.pk_customer
select sum(ttmoney), t.pk_customer, add_months( to_date(min(t.ordertime),'yyyy-MM-dd HH24:mi:ss'), -1)
from table t ,(select min( t.ordertime) D from table) A
where t.ordertime between add_months(A.D, -1) and A.D
group by t.pk_customer