如何根据一个关键字将多行数据合并一行显示
例如将
user_id,month,info1,info2
test1,8,test1info18,test1info28
test2,8,test2info18,test2info28
test1,9,test1info19,test1info29
test2,9,test2info19,test2info29
合并为
user_id,info1_8,info2_8,info1_9,info2_9
test1,test1info18,test1info28,test1info19,test1info29
test2,test2info18,test2info28,test2info19,test2info29
例如将
user_id,month,info1,info2
test1,8,test1info18,test1info28
test2,8,test2info18,test2info28
test1,9,test1info19,test1info29
test2,9,test2info19,test2info29
合并为
user_id,info1_8,info2_8,info1_9,info2_9
test1,test1info18,test1info28,test1info19,test1info29
test2,test2info18,test2info28,test2info19,test2info29
可惜是varchar2型的,不会整了
max(decode(month,8,info1)) info1_8,
max(decode(month,8,info2)) info2_8,
max(decode(month,9,info1)) info1_9,
max(decode(month,9,info2)) info2_9
from table
group by user_id
(Select info1 From test a Where a.Month =8 And user_id = 'test1') into1_8,
(Select info2 From test a Where a.Month =8 And user_id = 'test2') into2_8,
(Select info1 From test a Where a.Month =9 And user_id = 'test1') into1_9,
(Select info2 From test a Where a.Month =9 And user_id = 'test2') into2_9
From test
Group By user_id