统计前数据为:
A,B
1,1
1,2
1,3
2,1
2,2
3,3
4,4
求一Oracle 语法统计后为:
A,B
1,123
2,12
3,34
A,B
1,1
1,2
1,3
2,1
2,2
3,3
4,4
求一Oracle 语法统计后为:
A,B
1,123
2,12
3,34
解决方案 »
- linux oracle runInstaller
- oracle 简单问题(急)
- oracle-pc where 中条件字段名过多错
- 急?删除临时表空间的数据文件?
- USERS01.DBF数据文件可能损坏,现在用 recover datafile 'D:\ORACLE\ORADATA\RAINBOW\USERS01.DBF'也不行,请高手指教,急!!!
- 555555555,终于出问题了,ORA-01081: cannot start already-running ORACLE - shut it down first
- 通常msn用哪个端口
- 哪里有Oracle下载。谢谢
- 请问如何启用Oracle TNSListener服务?
- c# 远程连接oracle
- 急!请教这个sql语句怎么写:两个条件查询,其中一个满足,另一个条件就不要加了
- 为什么只安装“Oracle9i Client 运行时”,“SQL Plus”连不上数据库
--oracle 10及以上
select A,replace(wm_concat(B),',','') B from table_name group by A;这类问题有三种方法,详细参考我的BLOG:http://blog.csdn.net/gelyon/archive/2010/09/20/5897608.aspx
select A,replace(wm_concat(B),',','') B from table_name group by A;--好东西
http://blog.csdn.net/gelyon/archive/2010/09/20/5897608.aspx
select a,wm_concat(b)over(partition by a order by b) b
row_number()over(partition by a order by b desc) rnfrom table)
where rn=1;
使用wm_concat的难点在于控制连接的顺序.
SQL> select deptno,wm_concat(empno) from emp group by deptno;
DEPTNO WM_CONCAT(EMPNO)
------ --------------------------------------------------------------------------------
10 7782,7839,7934
20 7369,7902,7876,7788,7566
30 7499,7698,7654,7844,7900,7521
SQL>
SQL> select deptno, empno
2 from (select deptno,
3 wm_concat(empno) over(partition by deptno order by empno) empno,
4 row_number() over(partition by deptno order by empno desc) rn
5 from emp)
6 where rn = 1;
DEPTNO EMPNO
------ --------------------------------------------------------------------------------
10 7782,7839,7934
20 7369,7566,7788,7876,7902
30 7499,7521,7654,7698,7844,7900
SQL>