写错了,更改为:
table1
name sl
---- ---
aaa 3
bbb 2
ccc 5
aaa 2
fff 7
bbb 1
table2:
name sl
----- ----
aaa 1
fff 6
aaa 1
怎样得出这样的结果:
name sl_1 sl_2 sl3
----- ---- ---- ----
aaa 5 2 3
bbb 3 0 3
ccc 5 0 5
fff 7 6 1
table1
name sl
---- ---
aaa 3
bbb 2
ccc 5
aaa 2
fff 7
bbb 1
table2:
name sl
----- ----
aaa 1
fff 6
aaa 1
怎样得出这样的结果:
name sl_1 sl_2 sl3
----- ---- ---- ----
aaa 5 2 3
bbb 3 0 3
ccc 5 0 5
fff 7 6 1
解决方案 »
- 关于oracle里role的问题
- Oracle中,在程序包中用函数调用存储过程,存储过程有返回值。
- 用游标异常的问题 希望有人解决
- 一个分组统计的问题,有没有高手来看看
- 在执行insert语句的说话出现下面错误
- 本贴只作讨论,有高手请指点:关于oracle中调用其他语言编写的com组件问题,参与者有分!
- 初学问题。
- 请问在ora8中字段类型是存在那个系统表中???(急!急!急!)
- 有没有什么命令,能够把这一张在A表空间的表转移到B表空间?
- 写sql,全校有6个年级,每个年级5个班,全校的各科成绩从高到低学生名单?
- 用export进行数据库备份的问题?
- ★★★★★ORACLE触发器的问题★★★★★
table1
name sl
---- ---
aaa 3
bbb 2
ccc 5
aaa 2
fff 7
bbb 1
table2:
name sl
----- ----
aaa 1
fff 6
aaa 1
怎样得出这样的结果:
name sl_1 sl_2 sl3
----- ---- ---- ----
aaa 5 2 3
bbb 3 0 3
ccc 5 0 5
fff 7 6 1
(select name,sum(s1) s1_1,(select sum(s1) from table2 where name=table1.name) sl_2 from table1 group by name)
我实际的两张表是这样的:
A表数据:
品牌 型号 规格 数量 单价 合计
10001 10003 100010 3 11300 33900
10001 10003 100010 1 11200 11200
10007 10019 100042 1 1 1
10007 10023 100046 11 23 253
10001 10003 100018 2 10200 20400
10001 10003 100027 4 11500 46000B表数据
品牌 型号 规格 数量 单价 合计
10001 10003 100010 1 12000 12000
10001 10003 100010 1 12500 12500
10001 10003 100010 1 12000 12000
10007 10019 100042 1 3 3
10007 10023 100046 2 30 60要得出的结果是:
品牌 型号 规格 A数量 B数量 库存数量(A数量 - B数量)
10001 10003 100010 4 3 1
10001 10003 100018 2 0 2
(select 品牌,型号,规格,sum(数量) s1_1,(select sum(数量) from table2 where 品牌=table1.品牌 and 型号=table1.型号 and 规格=table1.规格) sl_2 from table1 group by 品牌,型号,规格)
这样写报错:
select cpmc,ppmc,xhmc,s1_1,s1_2,(s1_1-s1_2) sl3 from
(select cpmc,ppmc,xhmc,sum(rksl) s1_1,(select sum(cksl) from v_kc_ckbb01 where
cpmc=v_kc_rkbb01.cpmc and ppmc=v_kc_rkbb01.ppmc and xhmc=v_kc_rkbb01.xhmc) sl_2
from v_kc_rkbb01 group by cpmc,ppmc,xhmc);执行后;连接到:
Oracle8 Enterprise Edition Release 8.0.5.0.0 - Production
PL/SQL Release 8.0.5.0.0 - ProductionSQL> select cpmc,ppmc,xhmc,s1_1,s1_2,(s1_1-s1_2) sl3 from
2 (select cpmc,ppmc,xhmc,sum(rksl) s1_1,(select sum(cksl) from v_kc_ckbb01 where
3 cpmc=v_kc_rkbb01.cpmc and ppmc=v_kc_rkbb01.ppmc and xhmc=v_kc_rkbb01.xhmc) sl_2
4 from v_kc_rkbb01 group by cpmc,ppmc,xhmc);
(select cpmc,ppmc,xhmc,sum(rksl) s1_1,(select sum(cksl) from v_kc_ckbb01 where
*
错误位于第2行:
ORA-00936: 缺少表达式
(select 品牌,型号,规格,sum(a.数量) s1_1,sum(b.数量) sl_2 from table1 a,table2 b where a.品牌=b.品牌(+) and a.型号=b.型号(+) and a.规格=b.规格(+) group by 品牌,型号,规格)
from
(select name,sum(s1) s1_1
from aaa
group by name) a,
(select a1.name,sum(bbb.s1) s1_2
from bbb,(select distinct name from aaa ) a1
where a1.name=bbb.name(+)
group by a1.name) b
where a.name=b.name