如何从oracle 11g中的一行中的不同列中获取值
How to get values from different columns in one row in oracle 11g
我有一个table有如下记录,如图
我想要这样的记录
cntry_1、cntry_2、cntry_3、cntry_4是根据第一个table的country_type_id。 country_type_id 1 = 列 cntry_1
您必须使用 PIVOT
才能找到您要查找的内容。你可以这样使用它:
SELECT *
FROM
(
SELECT t.[Business name],
t.is_default,
t.is_active,
t.context,
t.country,
t.country_type_id
FROM TableName t
) src
PIVOT
(
MAX(Country)
FOR country_type_id IN ([1], [2], [3], [4])
) piv
看这里 -> http://rextester.com/HUK42854
希望对您有所帮助!!!
我有一个table有如下记录,如图
我想要这样的记录
cntry_1、cntry_2、cntry_3、cntry_4是根据第一个table的country_type_id。 country_type_id 1 = 列 cntry_1
您必须使用 PIVOT
才能找到您要查找的内容。你可以这样使用它:
SELECT *
FROM
(
SELECT t.[Business name],
t.is_default,
t.is_active,
t.context,
t.country,
t.country_type_id
FROM TableName t
) src
PIVOT
(
MAX(Country)
FOR country_type_id IN ([1], [2], [3], [4])
) piv
看这里 -> http://rextester.com/HUK42854
希望对您有所帮助!!!