2017-04-25 89 views
-3

我只有一個表兒童祖父母的關係無論是在SQL或Qlik感

enter image description here

從上表中我需要找出child_ID的祖父母。

輸出必須像下面

enter image description here

請讓我知道無論是在SQL或Qlik意義的代碼。

在此先感謝。

+1

你可以分享你迄今爲止所嘗試過的嗎? – gabe3886

+1

我不清楚child_id d是否有祖父母?我想這應該只適用於child_id c的情況。或者我錯過了什麼? – Kevin

+1

怎麼來child_id b的parent_id和grandparent_id是'a'?他們如何能夠相同? –

回答

0

從你的例子很難判斷你實際上想做什麼,但我假設你正在嘗試創建一個Hierarchy。

在Qlik,你正在尋找被稱爲Hierarchy

對於你的榜樣是什麼,請參見下面的腳本:

Data: 
LOAD * INLINE [ 
    Parent_ID, Child_ID 
    a, b 
    b, c 
    c, d 
    d, e 
]; 

Hierarchy (Child_ID, Parent_ID, Title, 'Parent') 
LOAD 
Parent_ID, 
Child_ID, 
Parent_ID as Title 
Resident Data; 

因爲你沒有一個標題,我用PARENT_ID作爲標題。