|
|
|
|
|
|
Re: How to retrieve parent and child in different columns when they exist in a single column. [message #639791 is a reply to message #639789] |
Thu, 16 July 2015 07:25 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
ankita.anand wrote on Thu, 16 July 2015 13:20
A01A1 ANTACIDS, here A01A is parent whose description is PLAIN. Why? Why is A01A the parent. Explain please.
Quote:So TC4_Code = A01A1 and TC4_Desc = ANTACIDS. This is an incomplete sentence, what are you trying to say here?
Quote:TC3_Code = A01A and TC3_desc = PLAIN Why? Explain the logic
Quote:Now for A01A , Parent is A01 whose description is STOMATOLOGIC. Why, what is the logic that dictates this?
Quote: So TC2_Code = A01 and TC2_Desc = STOMATOLOGIC Based on what logic?
etc etc. You get the idea.
|
|
|
|
|
|
|
|
|
|
Re: How to retrieve parent and child in different columns when they exist in a single column. [message #639802 is a reply to message #639797] |
Thu, 16 July 2015 08:17 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
There is probably an easier/ more efficient/ tidier/ nicer way of doing this but:
with t as
(select text
, case
when substr(text, 4, 1)= ' '
then rtrim(substr(text, 1,3), '0')
else rtrim(substr(text, 1,5), '0')
end code
, substr(text, 7) descript
from lc_load
)
, t2 as
(select
case length(t.code)
when 1
then 1
when 3
then 2
when 4
then 3
when 5
then 4
end lvl
, t.*
from t
)
select t2_4.code
, t2_4.descript
, t2_3.code
, t2_3.descript
, t2_2.code
, t2_2.descript
, t2_1.code
, t2_1.descript
from t2 t2_1
join t2 t2_2
on t2_1.code = substr(t2_2.code, 1, 1)
join t2 t2_3
on t2_2.code = substr(t2_3.code, 1, 3)
join t2 t2_4
on t2_3.code = substr(t2_4.code, 1, 4)
where t2_1.lvl = 1
and t2_2.lvl = 2
and t2_3.lvl = 3
and t2_4.lvl = 4
|
|
|
|
|