表 a
type 有三种 a,b,c
pid type amount date
101 a 20 20010101
103 b 5 20010103
101 c 4 20010104
101 a 3 20010103
103 c 5 20010201根据表a生成 表b,其中是根据pid分组汇总各自的type为a,b,c的总数,然后统计各id的type的总数allAmount
pid typeA typeB typeC allAmount
101 23 0 4 27
103 0 5 5 10
应该怎么写,效率最高.多谢
type 有三种 a,b,c
pid type amount date
101 a 20 20010101
103 b 5 20010103
101 c 4 20010104
101 a 3 20010103
103 c 5 20010201根据表a生成 表b,其中是根据pid分组汇总各自的type为a,b,c的总数,然后统计各id的type的总数allAmount
pid typeA typeB typeC allAmount
101 23 0 4 27
103 0 5 5 10
应该怎么写,效率最高.多谢
解决方案 »
- 问个关于oracle主键的问题
- ORACLE如何查询FUNCTION是否被锁住
- oracle的锁是不是这个意思?
- 求教:根据表A,中Name列的值,显示表B中,在a.name里的属性的值,两表建关联.
- 为什么oracle 主页进入不了,plsql没有监听程序,我前两天刚重装的。
- oracle的审计功能能看到执行的sql语句是什么吗
- 怎么在存储过程里面调用链路的存储过程
- 如果将这名MSSQL的UPDATE语句转为ORACLE
- SQL数据更新问题
- 有关oracle的一个维护问题?(100分)
- 记事本里的数据导入oracle数据库------------------标题要长-----------------
- oracle函数改mysql,需要注意哪一些?
select pid,count(decode(type,'a',1)),count(decode(type,'b',1)),count(decode(type,'c',1)),sum(amount)
from tablea
group by pid
sum(decode(type,'c',amount,0)) typeC,sum(amount) allAmount from temp group by pid
select 101 pid,'a' type,20 amount,'20010101' "date" from dual
union all
select 103 pid,'b' type,5 amount,'20010103' "date" from dual
union all
select 101 pid,'c' type,4 amount,'20010104' "date" from dual
union all
select 101 pid,'a' type,3 amount,'20010103' "date" from dual
union all
select 103 pid,'c' type,5 amount,'20010201' "date" from dual
)
select pid, sum(decode(type,'a',amount,0)) typeA,sum(decode(type,'b',amount,0)) typeB,
sum(decode(type,'c',amount,0)) typeC,sum(amount) allAmount from temp group by pid
sum(decode(type,'b',amount)) typeb,
sum(decode(type,'c',amount)) typec,
sum(amount) allAmount
from tb
group by pid