易截截图软件、单文件、免安装、纯绿色、仅160KB

请教sql语句。 - Oracle / 开发

我有一个表,结构是这样。
  转出 单位 转入单位 笔数 金额
date(主) outid(主) inid(主) num amt
2009 1 2 1 500 为 1 单位 在2009年给 2 转出 1 笔 500元 
2009 1 3 1 100 为 1 单位 在2009年给 3 转出 1 笔 100元 
2009 1 4 3 200 为 1 单位 在2009年给 4 转出 3 笔 200元
2009 2 1 2 100 为 2 单位 在2009年给 1 转出 2 笔 100元
2009 4 1 1 100 为 4 单位 在2009年给 1 转出 1 笔 100元
2009 3 1 2 100 为 3 单位 在2009年给 1 转出 2 笔 100元


我需要查出结果如下,查询出2,3,4单位给1转出的,和由1转入的:

单位 转出笔数 转出金额 转入笔数 转出金额
id date outnum outamt innum inamt 
2 2009 2 200 1 500
3 2009 2 100 1 100  
4 2009 1 100 3 200

请问sql怎么写?
多谢。。。。


select outid as id,date,sum(num),sum(amt)
from tb
where outid in (2,3,4) and inid =1]
group by outid,date


看晕了,数据是不是不对啊

应该是转给1的和由1转出的吧

数据不对啊

SQL code



Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/


相关问答:

是oracle的bug么?散分了! - Oracle / 基础和管理

本来要写个update语句
update table_a A
  set A.flag=1
  where A.id in (select B.id from table_b B)
结果误写成
update table_a A
  set A.flag=1
  where ......

Oracle 数据导出问题 - Oracle / 高级技术

exp user/password@dbname file=c:\table.dmp tables=jbitaku,jbitakum grants=y
然後按回車鍵 說明:  user/password@dbname  分別表示用戶名,密碼和服務名 f ......

sql 存储过程

我要做一个定点事件,是每天晚上12点就把三个表里的信息放入一个表里,我想用存储过程来写,怎么写呢?,那位高手帮帮忙吧,非常感谢!

用户名是唯一的
表A  字段
用户名:Name  ,邮箱:Ema ......

java怎么连接Oracle,急啊 - Java / Java相关

private static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME = "sys";
private static final String PASSWORD = "s ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号