Convert Tree into Table columns

76 views
Skip to first unread message

Shashwat Singh

unread,
Mar 15, 2021, 5:29:34 AM3/15/21
to Kdb+ Personal Developers
Hi All,

I have a problem statement where I need to convert Tree kind of rows into columns.
 
For Ex:-

I have a table Tree where I have rows as follows :

Rule       | Key         | Value
Rule1      | Key1      | Val1
Rule1      | Key2      | Val2
Rule2      | Key1      | Val3
Rule2      | Key2      | Val4
Rule3      | Key1      | Val5
Rule3      | Key2      | Val6
Rule3      | Key3       | Val7

Now I want to convert the unique keys as a column to my output tree and values be the row value.

Output Table :-

Rule       | Key1         | Key2         | Key3
Rule1     | Val1          | Val2          | 
Rule2     | Val3          | Val4          | 
Rule3     | Val5          | Val6          |  Val7


Basically, I want to group all rules together, create columns out of all unique keys and respective values.

Not sure how to do it in kdb. Can somebody help here?

KDB Dev

unread,
Mar 15, 2021, 5:53:18 AM3/15/21
to Kdb+ Personal Developers
I got the answer post posting this... We can use pivot.. Thanks to KDB...

Ajay Rathore

unread,
Mar 15, 2021, 5:53:24 AM3/15/21
to personal...@googlegroups.com


exec distinct[t`Key]#Key!Val by rule:rule from t



--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/personal-kdbplus/a21235b5-822a-46ec-a70a-3bd2a807e1den%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages