请教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/
相关问答:
本来要写个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 ......
exp user/password@dbname file=c:\table.dmp tables=jbitaku,jbitakum grants=y
然後按回車鍵 說明: user/password@dbname 分別表示用戶名,密碼和服務名 f ......
我要做一个定点事件,是每天晚上12点就把三个表里的信息放入一个表里,我想用存储过程来写,怎么写呢?,那位高手帮帮忙吧,非常感谢!
用户名是唯一的
表A 字段
用户名:Name ,邮箱:Ema ......
private static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME = "sys";
private static final String PASSWORD = "s ......