动态查询语句

thunderwolf 2010-03-13 12:08:21
报表格式如下
输入是 开始月份(开始月份默认为1月),结束月份

营业部名称 1月有效户数 …… X月有效户 合计

合计

PS:如果是输入1月和9月,则上面的统计就是1月到9月
表tabaa字段如下为
RQ 日期
YYB 营业部
LSH 流水号
YWLB 业务类别

当YWLB为190时,为本月的有效用户

上面的过程怎么写呢?请高手赐教
...全文
116 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
notepad 2010-03-15
  • 打赏
  • 举报
回复
路过 学习。
小灰狼W 2010-03-14
  • 打赏
  • 举报
回复
这个合计是1月到9月的有效用户数,还是1到9月每个月的有效用户数简单相加?
前者的话
你的表结构什么写得也不清楚,我大体的代码写下

create or replace procedure ...(start_month in varchar2,end_month in varchar2,cur out sys_refcursor)
as
sqlstr varchar2(4000):='select yyb';
begin
for cur1 in(select add_months(to_date(start_month,'yyyymm'),rownum-1)mon
from dual connect by rownum<=months_between(to_date(end_month,'yyyymm'),to_date(start_month,'yyyymm'))+1)
loop
sqlstr:=sqlstr||',count(decode(to_char(rq,''yyyymm''),'''||to_char(cur1.mon,'yyyymm')||''',1)) "'||to_char(cur1.mon,'yyyy"年"mm"月"')||'"';
end loop;
open cur for sqlstr||' from tabaa where twlb=''190''';
end;
  • 打赏
  • 举报
回复

create table table_name(
yyb_name varchar2(50),营业部名称
start_date number(8),--开始时间
end_date number(8),--结束时间
count_users number(10)--有效户数合计
)
create or replace procedure proc_name(f_month in number,l_month in number)
/**************
f_month为开始日期默认为年初话,如201001
l_month为结束日期
在这里用number类型了
**************/
is
insert into table_name--中间表
(yyb_name,营业部名称
start_date,--开始时间
end_date,--结束时间
count_users--有效户数合计)
select yyb,
f_month,
rq,
count(ywlb)
from your_table_name y
where y.rq <= l_month
and y.rq >= f_month
and y.ywlb = '190';
commit;
......
--你的其他需求
end;

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧