一张表中有item,type,value三列,type有5中类型,如何用sql语句查询出每一个item不同type的value
查询后的数据格式如下itemtype1type2type3type4type5item1valuevaluevaluevaluevalueitem2valuevaluev...
查询后的数据格式如下
item type1 type2 type3 type4 type5
item1 value value value value value
item2 value value value value value
....... 展开
item type1 type2 type3 type4 type5
item1 value value value value value
item2 value value value value value
....... 展开
2015-08-12 · 知道合伙人软件行家
关注
展开全部
展开全部
oracle10g及以上:
select item,replace(WMSYS.WM_CONCAT(value),',',' ') value
from table1
group by item
SQL:
SELECT item,max(value) city
FROM
(SELECT item,sys_connect_by_path(value,' ') value
FROM
(SELECT item,value,item||rn rchild,item||(rn-1) rfather
FROM
(SELECT test.item,test.value,row_number() over (PARTITION BY test.item ORDER BY test.value) rn
FROM test))
CONNECT BY PRIOR rchild=rfather START WITH rfather LIKE '%0')
GROUP BY item
select item,replace(WMSYS.WM_CONCAT(value),',',' ') value
from table1
group by item
SQL:
SELECT item,max(value) city
FROM
(SELECT item,sys_connect_by_path(value,' ') value
FROM
(SELECT item,value,item||rn rchild,item||(rn-1) rfather
FROM
(SELECT test.item,test.value,row_number() over (PARTITION BY test.item ORDER BY test.value) rn
FROM test))
CONNECT BY PRIOR rchild=rfather START WITH rfather LIKE '%0')
GROUP BY item
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询