首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

请问一个SQL写法

2012-08-24 
请教一个SQL写法请教下各位一个SQL写法,突然想不出来了p_name sun_p_nameA111A122C333D555B566B3221321显

请教一个SQL写法
请教下各位一个SQL写法,突然想不出来了
p_name sun_p_name
A 111
A 122
C 333
D 555
B 566
B 3221321

显示为:
p_name sun_p_name
A 111
  122
B 566
  3221321
C 333
D 555

[解决办法]
对2个字段都group by,并且把p_name字段升序
[解决办法]
try
-----------------------------------------------

WITH t AS
 (SELECT 'A' AS p_name, '111' AS sun_pname
FROM dual
UNION ALL
SELECT 'A' AS p_name, '122' AS sun_pname
FROM dual
UNION ALL
SELECT 'C' AS p_name, '333' AS sun_pname
FROM dual
UNION ALL
SELECT 'D' AS p_name, '555' AS sun_pname
FROM dual
UNION ALL
SELECT 'B' AS p_name, '566' AS sun_pname
FROM dual
UNION ALL
SELECT 'B' AS p_name, '3221321' AS sun_pname FROM dual)

SELECT decode(row_number() over(PARTITION BY p_name ORDER BY sun_pname), 1, p_name, ''), sun_pname FROM t

热点排行