易截截图软件、单文件、免安装、纯绿色、仅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/


相关问答:

求一SQL - MS-SQL Server / 基础类

表如下
教室ID 座位数 开始时间 结束时间 2009年1月1日 2009年1月2日 2009年1月3日
  101 50 08:00 08:30 30 40 50  
  101 50 09:00 ......

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

是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 / 基础和管理

我在创建数据库的时候用的名字为oracle10,但是创建好后,在默认的目录下显示的名称却是oracle10g,这是为什么?
你看的 10g是安装目录吧 

SQL> select name from v$database;
NAME
---------
ORCL ......

oracle 10g安装到85%时报错

各位oracle高手,请教一下为什么oracle 10g在安装到百分之八十五的时候就报错不能继续安装?

内存多大? 重新下个数据库安装试试..

引用
各位oracle高手,请教一下为什么oracle 10g在安装到百分之八十五的时 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号