-
ungroup, xgroup, lj
I have more than one matching rows on keyed column, so I’d like to show all the data
What’s the easiest/efficient way to achieve my final result please? Thank you
However, ungroup will remove rows that ain’t matched:q)t1 col1 col2 col3 -------------- a 1 11 b 2 22 c 3 33 d 8 88 q)t2 col1 col4 col5 -------------- a 4 44 a 5 55 b 6 66 c 7 77 //ungroup removes the col1=d q)t1 lj `col1 xgroup t2 col1 col2 col3 col4 col5 -------------------------------- a 1 11 4 5 44 55 b 2 22 ,6 ,66 c 3 33 ,7 ,77 d 8 88 `long$() `long$() q)ungroup t1 lj `col1 xgroup t2 col1 col2 col3 col4 col5 ------------------------ a 1 11 4 44 a 1 11 5 55 b 2 22 6 66 c 3 33 7 77 q) //I want to achieve this q)t:ungroup t1 lj `col1 xgroup t2 q)res:t upsert t1 except ?[t;();0b;{x!x} cols t1] q)res col1 col2 col3 col4 col5 ------------------------ a 1 11 4 44 a 1 11 5 55 b 2 22 6 66 c 3 33 7 77 d 8 88 <br></pre><pre>//My 2nd question is that after I have the above res, I want to enrich res again but it fails with a type error: q)t3:([] col1:`d`d;col4:0 0;col5:0 00) q)t3 col1 col4 col5 -------------- d 0 0 d 0 0 q)res lj `col1 xgroup t3 'type [0] res lj `col1 xgroup t3 ^ q))\
- This discussion was modified 1 day, 9 hours ago by kdb_newbie.
Log in to reply.