Oracle11g 如何在oracle中将多行中的值插入到记录中?
我有一张这样的桌子:Oracle11g 如何在oracle中将多行中的值插入到记录中?,oracle11g,insert-into,Oracle11g,Insert Into,我有一张这样的桌子: id field value ---------------------- 1845 name john 1845 post manager 1845 birth 1980 1846 name alex 1846 post employee 1846 birth 1986 id name post bir
id field value
----------------------
1845 name john
1845 post manager
1845 birth 1980
1846 name alex
1846 post employee
1846 birth 1986
id name post birth
----------------------------------------
1845 john manager 1980
1846 alex employee 1986
.
.
.
我想要一个如下所示的结果集:
id field value
----------------------
1845 name john
1845 post manager
1845 birth 1980
1846 name alex
1846 post employee
1846 birth 1986
id name post birth
----------------------------------------
1845 john manager 1980
1846 alex employee 1986
.
.
.
oracle中有什么方法可以做到这一点吗?假设ID字段对于给定的姓名、职位和出生具有相同的编号,下面的查询可能会对您有所帮助
select
distinct
id,
(select value from test where id = a.id and field = 'name') as name,
(select value from test where id = a.id and field = 'post') as post,
(select value from test where id = a.id and field = 'birth') as birth
from test a
请注意,对于以下情况,如果同一ID有两个名称,则上述查询将不起作用:
id field value
----------------------
1845 name john
1845 post manager
1845 birth 1980
1845 name alex
1845 post employee
1845 birth 1986
例如: