select a.code, sum(inmoney),sum(outmoney),min(qyname),kind
from a,b,c,d
where b.code = a.code(+) and b.code = c.code(+) and a.qycode = d.qycode
group by kind , a.code
from a,b,c,d
where b.code = a.code(+) and b.code = c.code(+) and a.qycode = d.qycode
group by kind , a.code
解决方案 »
- Oracle配置问题
- 小白问题.能不能写一段sql可以拿到上个星期的星期一和这个月的1号
- 开始做oracle 数据库开发了 !
- 如何标记记录的多个状态,select的时候取余作为条件对性能影响大不大
- 从sqlserver向oracle导数据的问题求教,谢谢!
- 高手急救!!!关于系统PATH问题!!!!
- 我在用DTS时,把文件文件的内容导到HELP表里(字段没有问题的),看不到SYSTEM用户的所有表,我在企业管理器里看了是HELP是SYSTEM的
- plsql运行下面的procedure时,当取出一张卡想显示当前处理的motoristid,该怎么修改?记得sql中用print
- 小弟這裡有個簡單問題..希望大家可以幫幫忙給點提示..(關於Form 的)..
- 请问这个sql该怎么写?谢谢
- 把数据从oracle往mysql里导怎么导啊???急!!!
- 怎样将一台机器上数据库中数据表和触发器,存储过程等复制到另一台机器的数据库中?
1 10 0001
1 20 0002
1 30 0001
从这个表可以看出,同一个code对应了多个qycode也就是多个qyname
如果楼主
“我想列出code,sum(inmoney),sum(outmoney),qyname,kind 按照大类(kind)和代码(code)分组得出上述数据列表,”
必然会用到qyname的分组,否则无法取qyname的值。不知道是不是楼主的要求有误
code sum(inmoney) sum(outmoney) qyname kind
1 10+30 1000+2000 张 1
1 20 1000+2000 王 1
2 10+20 1000 陈 1
3 1500 2
b: code outmoney
1 1000
1 2000
2 1000
3 1500
这个表和qyname一点关系也没有,如何处理
sum(outmoney)
1000+2000
1000+2000
from
(
select b.code,isnull(a.inmoney,0) as inm,isnull(b.outmoney,0) as outm ,isnull(d.qyname,'') as qyname
from a right outer join b
on a.code=b.code
left outer join d
on a.qycode=d.qycode
) t
left outer join c
on t.code=c.code
group by t.code,t.qyname,c.kind--结果
code inall outall qyname kind
----------- ----------- ----------- ---------- -----------
1 40 3000 wang 1
1 80 6000 zhang 1
2 30 2000 chen 1
3 0 1500 2(4 row(s) affected)
楼主先修改一下表吧
1 20 1000+2000 王 1
select t.code code,(select sum(inmoney) from a where code=t.code and qycode=t.qycode) suminmoney,(select sum(outmoney) from b where code=t.code) sumoutmoney,(select qyname from d where qycode=t.qycode) qyname,(select kind from c where code=t.code) kind from (select b.code,a.qycode from a,b where a.code(+)=b.code group by b.code,a.qycode) t;
结果如下:
CODE SUMINMONEY SUMOUTMONEY QYNAME KIND
---------- ---------- ----------- -------------------- ----------
1 40 3000 张 1
1 20 3000 王 1
2 30 1000 陈 1
3 1500 2
(
select c.code,x.inmoney,x.qyname,c.kind from c,
(
select a.qycode,a.code,a.inmoney,d.qyname from
(
select code,qycode,sum(inmoney) inmoney from a
group by code,qycode
) a,d
where a.qycode=d.qycode
) x
where c.code=x.code(+)
) s,
(
select code,sum(outmoney) outmoney from b
group by code
) t
where s.code=t.code;