请教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/
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
我要做一个定点事件,是每天晚上12点就把三个表里的信息放入一个表里,我想用存储过程来写,怎么写呢?,那位高手帮帮忙吧,非常感谢!
用户名是唯一的
表A 字段
用户名:Name ,邮箱:Ema ......
需求如下:
a表:
p_id status
1 0
2 0
b表
rec_id pid purchase_qty receive_qty flag
1 1 10 10 0
2 ......