有个表查出来的数据是如下显示的
名称 位置
1 a
1 b
1 c
2 d
2 e
怎么直接用sql语句让其显示出 固定四行,没有的用null
名称 位置1 位置2 位置 3
1 a b c
2 d e null
------解决思路----------------------
with t as (
select 名称,位置,row_number()over(partition by 名称 order by 位置) rn
from table 1
)
select 名称,
max(decode(rn,1,位置)) 位置1,
max(decode(rn,2,位置)) 位置2,
max(decode(rn,3,位置)) 位置3
from t
group by 名称