select T.hh,LAST_DAY(T.timedate),SUM(t.outamt)
from bb_busy t
where t.timedate = add_months(t.close_dt,-1)
group by T.hh,LAST_DAY(T.timedate) 以上是我的问题SQL,T表中HH字段代表机构号,有153家,timedate字段是时间,close_dt是关停时间。
我现在要算这153家机构在关停时间前一个月 和 前三个月的 outamt值,可是按上面那么写是不对的,搞不懂了,希望有大能帮忙看一下、 谢谢了。
from bb_busy t
where t.timedate = add_months(t.close_dt,-1)
group by T.hh,LAST_DAY(T.timedate) 以上是我的问题SQL,T表中HH字段代表机构号,有153家,timedate字段是时间,close_dt是关停时间。
我现在要算这153家机构在关停时间前一个月 和 前三个月的 outamt值,可是按上面那么写是不对的,搞不懂了,希望有大能帮忙看一下、 谢谢了。
select T.hh, SUM(t.outamt)
from bb_busy t where t.timedate > add_months(t.close_dt,-1)
group by T.hh;--关停时间前三个月的outamt值
select T.hh, SUM(t.outamt)
from bb_busy t where t.timedate > add_months(t.close_dt,-3)
group by T.hh;