select in,sum(id*value) as suminvalue,sum((1-id)*value) as sumoutvalue
from (
select 1 as id,table2.in as in,table2.value
from table1,table2
where table1.in=table2.in
union all
select 0 as id,table2.out as in,table2.value
from table1,table2
where table1.in=table2.out
) t0
group by id;
from (
select 1 as id,table2.in as in,table2.value
from table1,table2
where table1.in=table2.in
union all
select 0 as id,table2.out as in,table2.value
from table1,table2
where table1.in=table2.out
) t0
group by id;
解决方案 »
- 请教关于oracle -3113错误
- oracle数据库文件目录设置在局域网其他机子上?
- 求一个语句?
- 高分求助,求一个ORACLE字符串处理过程!(100分)在线等待!
- 哭诉: 数据库为什么会当掉?error 221
- 哪位大哥能帮帮忙:PLSQL Developer连不上另一个数据库!!!!!
- 求教一个菜鸟问题 数据导入。。急救啊!.dmp
- 大家好,真对一个用户能否将他的权限设置为一个表空间的操作
- 请教,想实现一个功能,sql不知道怎么写好
- 高手进!!!!请问Oracle的common.inc文件在哪个文件夹?
- 紧急求助:ORACLE存储过程中动态SQL
- 请问将SQL server 数据库转为Oracle 数据库困难吗?
from t1,(select sum(value) sumin , t1.v_in
from t1,t2
where t1.v_in=t2.v_in group by t1.v_in) t3,
(select sum(value) sumout , t1.v_in
from t1,t2
where t1.v_in=t2.v_out group by t1.v_in) t4
where t1.v_in=t3.v_in and t1.v_in=t4.v_in
这句话可以吗
FROM table1 t1,
(SELECT t2In,SUM(t2value) SumInValue FROM table2 GROUP BY t2In)SumIn,
(SELECT t2Out,SUM(t2value) SumOutValue FROM table2 GROUP BY t2Out)SumOut
WHERE SumIn.t2In=t1.t1in AND SumOut.t2Out=t1.t1in
1.上述SQL经过测试(ORACLE 9i);
2.因为保留字的缘故,对列名作了修改;
FROM
(SELECT a.in,sum(b.value) sumin FROM table1 a,table2 b WHERE a.in=b.in GROUP BY a.in) a,
(SELECT a.in,sum(b.value) sumout FROM table1 a,table2 b WHERE a.in=b.out GROUP BY a.in) b
WHERE a.in=b.in