select t.Month_id,s.csdn,sum(s.a)
from
month t , cost s
where
s.month_id = t.month_id
AND t.Month_id >= SUBSTR('20110701',1,6)
AND t.Month_id <= SUBSTR('20110731',1,6)
group by
t.Month_id,s.csdn
怎么查询出 201106年的数据来。。。。。。
AND t.Month_id >= SUBSTR('20110701',1,6)
AND t.Month_id <= SUBSTR('20110731',1,6)
这个是时间是手工改变的
------解决方案--------------------
where t.Month_id='201106'
就行了吧.
------解决方案--------------------
Decalre @MM Char(6)
Set @MM = '201106'
select t.Month_id,s.csdn,sum(s.a)
from
month t , cost s
where
s.month_id = t.month_id
AND t.Month_id = @MM
group by
t.Month_id,s.csdn
------解决方案--------------------
SUBSTR--Oracle?
------解决方案--------------------
to_char(Month_id, 'yyyy/mm ')=‘201106’
------解决方案--------------------
本帖最后由 roy_88 于 2011-11-06 00:19:26 编辑
Month_id为日期时
to_char(Month_id, 'yyyymm ')=‘201106’--少打了一个符号改改
or
to_char(add_months(sysdate,-1),'yymm')--当前系统上个月
------解决方案--------------------
如果t.Month_id 是日期型
AND t.Month_id >= SUBSTR('20110701',1,6)
AND t.Month_id <= SUBSTR('20110731',1,6)
-->
AND to_char(t.Month_id,'YYYYMM') = to_char(trunc(sysdate , 'MM') - 1 , 'YYYYMM')