各位帮忙优化一下

pldongdong 2009-02-16 02:36:37
create table test1
(
aa varchar2(8),
bb number(10),
cc number(10),
dd number(10),
ee number(10)
)
create table test2
(
m_aa varchar2(8),
m_nn varchar2(8),
)

insert into test3(colu1,colu2,colu3,colu4,colu5)
select
test2.m_nn as colu1,
(select sum(bb) from test1 where test1.aa like test2.m_aa ||'%') as colu2,
(select sum(cc) from test1 where test1.aa like test2.m_aa ||'%') as colu3,
(select sum(dd) from test1 where test1.aa like test2.m_aa ||'%') as colu4,
(select sum(ee) from test1 where test1.aa like test2.m_aa ||'%') as colu5
from test2
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fuyou001 2009-02-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hdhai9451 的回复:]
insert into test3(colu1,colu2,colu3,colu4,colu5)
select a.m_nn,sum(b.bb) bb,sum(b.cc) cc,sum(b.dd) dd,sum(b.ee) ee
from test2 a,test1 b
where b.aa like a.m_aa||'%' --只返回符合此条件的记录,有可以不是所有记录
group by a.m_nn
[/Quote]
只有引用的内容不允许回复!!
pldongdong 2009-02-16
  • 打赏
  • 举报
回复
按一楼的做法好像不能返回test2表中所有记录
pldongdong 2009-02-16
  • 打赏
  • 举报
回复
恩,谢谢,试试看
Andy__Huang 2009-02-16
  • 打赏
  • 举报
回复
insert into test3(colu1,colu2,colu3,colu4,colu5)
select a.m_nn,sum(b.bb) bb,sum(b.cc) cc,sum(b.dd) dd,sum(b.ee) ee
from test2 a,test1 b
where b.aa like a.m_aa||'%'
group by a.m_nn

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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