17,075
社区成员
发帖
与我相关
我的任务
分享
select sum(sda.cpcconsume / 100 / (to_date('20140630', 'yyyymmdd') -
to_date('20140101', 'yyyymmdd') + 1))
from queryman.stat_day_account sda
where sda.createdate >= to_date('20130101', 'yyyymmdd')
and sda.createdate <= to_date('20130630', 'yyyymmdd')
having(sum(sda.cpcconsume) / 100) >= 500;
[/quote]
多谢帮助。我想要计算每个月的平均收益,你的答案计算的是这6各月的平均收益吧[/quote]
你是在其他程序中调用报错还是在SQL执行的时候报错?[quote=引用 2 楼 wmxcn2000 的回复:]-- LZ 执行下面的语句,也出错吗? select to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd') from dual
[quote=引用 楼主 march_on 的回复:] 我的需求是这样的:计算2013 1月到6月之间每个月的平均收益。 我写的语句是这样的:我不知道怎么一下子计算出6各月的数据,所以先算1月份的。结果执行的时候提示算数运算导致溢出。问题出在计算每个月多少天那里 了,我把 select sum( sda.cpcconsume/100/to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd') ) from queryman.stat_day_account sda where sda.createdate >= to_date('20130101', 'yyyymmdd') and sda.createdate < to_date('20130131', 'yyyymmdd') having (sum(sda.cpcconsume) / 100 )>=500换成31还是同样的错误,但是换成30后却是正常的,求教应该怎么修改呢? to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd')
select sum(sda.cpcconsume / 100 / (to_date('20140630', 'yyyymmdd') -
to_date('20140101', 'yyyymmdd') + 1))
from queryman.stat_day_account sda
where sda.createdate >= to_date('20130101', 'yyyymmdd')
and sda.createdate <= to_date('20130630', 'yyyymmdd')
having(sum(sda.cpcconsume) / 100) >= 500;
[/quote]
多谢帮助。我想要计算每个月的平均收益,你的答案计算的是这6各月的平均收益吧-- LZ 执行下面的语句,也出错吗? select to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd') from dual
我的需求是这样的:计算2013 1月到6月之间每个月的平均收益。 我写的语句是这样的:我不知道怎么一下子计算出6各月的数据,所以先算1月份的。结果执行的时候提示算数运算导致溢出。问题出在计算每个月多少天那里 了,我把 select sum( sda.cpcconsume/100/to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd') ) from queryman.stat_day_account sda where sda.createdate >= to_date('20130101', 'yyyymmdd') and sda.createdate < to_date('20130131', 'yyyymmdd') having (sum(sda.cpcconsume) / 100 )>=500换成31还是同样的错误,但是换成30后却是正常的,求教应该怎么修改呢? to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd')
select sum(sda.cpcconsume / 100 / (to_date('20140630', 'yyyymmdd') -
to_date('20140101', 'yyyymmdd') + 1))
from queryman.stat_day_account sda
where sda.createdate >= to_date('20130101', 'yyyymmdd')
and sda.createdate <= to_date('20130630', 'yyyymmdd')
having(sum(sda.cpcconsume) / 100) >= 500;
-- LZ 执行下面的语句,也出错吗?
select to_char( last_day( to_date('20130101','yyyy-mm-dd') ),'dd') from dual
select to_char(sda.createdate,'yyyymm') 月份,
sum(sda.cpcconsume)/100/to_number(to_char(last_day( to_date(to_char(sda.createdate,'yyyymm') ||'01','yyyymmdd') ),'dd'))
from queryman.stat_day_account sda
group by to_char(sda.createdate,'yyyymm')