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

Sql排序 - MS-SQL Server / 基础类

我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......

oracle 10g安装到85%时报错

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

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

引用
各位oracle高手,请教一下为什么oracle 10g在安装到百分之八十五的时 ......

sql 截取字符串

我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......

linux下C语言开发oracle的问题。

两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库 
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号