当前位置: 代码迷 >> Oracle管理 >> 求大神指导一个sql查询有关问题
  详细解决方案

求大神指导一个sql查询有关问题

热度:209   发布时间:2016-04-24 04:07:21.0
求大神指导一个sql查询问题
有个表查出来的数据是如下显示的
名称   位置
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 名称
  相关解决方案