Source:
LAN COD DESC
C 1234 Description in spanish
V 1234 Description in english
C 1235 Description in spanish
V 1235 Description in english
C 1236 Description in spanish
V 1236 Description in english
Created View:
COD, DESC in spanish, DESC in english
I think you want conditional aggregation:
select cod,
max(case when language = 'C' then description end),
max(case when language = 'V' then description end)
from t
group by cod;
Use a PIVOT
:
SELECT *
FROM table_name
PIVOT (
MAX( descr )
FOR lan IN (
'C' AS Spanish,
'V' AS English
)
)
Which, for your sample data:
CREATE TABLE table_name ( LAN, COD, DESCR ) AS
SELECT 'C', 1234, 'Description in spanish' FROM DUAL UNION ALL
SELECT 'V', 1234, 'Description in english' FROM DUAL UNION ALL
SELECT 'C', 1235, 'Description in spanish' FROM DUAL UNION ALL
SELECT 'V', 1235, 'Description in english' FROM DUAL UNION ALL
SELECT 'C', 1236, 'Description in spanish' FROM DUAL UNION ALL
SELECT 'V', 1236, 'Description in english' FROM DUAL;
Outputs:
\n COD | SPANISH | ENGLISH \n---: | :--------------------- | :--------------------- \n1234 |Description in spanish | Description in english\n1236 |Description in spanish | Description in english\n1235 |Description in spanish | Description in english\n
If you want it as a VIEW
then:
CREATE VIEW view_name AS
SELECT *
FROM table_name
PIVOT (
MAX( descr )
FOR lan IN (
'C' AS Spanish,
'V' AS English
)
)
db<>fiddle here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.