参考一下下边的
select id,bpid1,bpid2 from(
select id,minbpid,maxbpid,
(select money from a where id=a1.id and bpid=a1.minbpid)bpid1,
(select money from a where id=a1.id and bpid=a1.maxbpid)bpid2
from (select id,,min(bpid) minbpid,max(bpid) maxbpid from a group by id) a1);
select id,bpid1,bpid2 from(
select id,minbpid,maxbpid,
(select money from a where id=a1.id and bpid=a1.minbpid)bpid1,
(select money from a where id=a1.id and bpid=a1.maxbpid)bpid2
from (select id,,min(bpid) minbpid,max(bpid) maxbpid from a group by id) a1);
解决方案 »
- 麻烦各位瞧瞧,按指定条数批量更新的问题.(所有分都给了.)
- 关于两个表的关联插入问题,请各位指教
- 急,求助:一个表中的10个字段数据,都涉及到5个代码表,如何高效率处理查询显示?
- 新手学Oracle的问题
- 如何创建用户和该用户能够操作的表空间!(急,在线等!)
- 难题:数据的同步?
- 高分求教:请问怎样把字段里的回车符在sql中去掉。急!在线等待。。。
- 安装时出现ora-12203:TNS:无法与目标连接,要求输入口令,怎么回事?????
- oracle9i能不能在xp下运行?
- ORACLE 10亿数据全文索引 与MSSQL 10亿数据 全文索引
- 如果在STUD_424中不允许修改XH,触发器将怎样改进?
- 如何查看oracle过程执行到什么程度了,谢谢
select id,sum(bpid1) bpid1,sum(bpid2) bpid2
from (
select id,sum(decode(bpid,1,money,0)) bpid1,sum(decode(bpid,2,money,0)) bpid2
from 表A
group by id
)
group by id
;
create table henry_test(id number(10),bpid number(10),money number(10));
insert into henry_test values (1,1,100);
insert into henry_test values (1,2,200);
--楼主所要的SQL语句
select id,sum(decode(bpid,1,money,0)),sum(decode(bpid,2,money,0)) from henry_test group by id;
结果如下:
ID SUM(DECODE(BPID,1,MONEY,0)) SUM(DECODE(BPID,2,MONEY,0))
----------- --------------------------- ---------------------------
1 100 200
----------- ---------- ----------
1 100 200