cancel
Showing results for 
Search instead for 
Did you mean: 

kind of join

kdb_queries
New Contributor
Hello Gurus,
I am facing an issue to join 2 tables. Below is me requirement.


q)t2:([]ticker:10?`IBM`GOOG`MSFT;time2:10?.z.t;sellP:10?10.0;vol2:10?10)
q)t1:([]ticker:10?`IBM`GOOG`MSFT;time1:10?.z.t;buyP:10?10.0;vol:10?10)
I have above 2 tables:
t1:
ticker time1 buyP vol
GOOG 01:48:39.333 4.84472701093182 5
GOOG 04:59:16.764 1.5322696138173342 3
GOOG 03:07:01.588 5.350922802463174 9
GOOG 04:56:25.010 4.573280378244817 5
GOOG 00:24:51.886 4.861546200700104 4
IBM 04:07:07.595 1.0393433482386172 7
MSFT 03:46:36.109 6.827999036759138 2
MSFT 02:06:39.013 0.0806252146139741 9
MSFT 03:22:49.917 1.0445117414928973 6
MSFT 06:28:41.239 3.3800970250740647 6

t2:
ticker time2 sellP vol2
GOOG 05:50:50.463 6.430982279125601 8
GOOG 04:58:27.048 3.867353042587638 3
GOOG 01:23:46.281 8.35506496252492 8
IBM 03:46:37.677 7.267809968907386 3
IBM 02:31:11.038 0.3668340714648366 7
IBM 02:13:45.275 6.708737732842565 5
IBM 01:06:15.890 6.78908244241029 6
MSFT 05:31:58.255 4.123170133680105 4
MSFT 01:53:56.122 9.877844415605068 1
MSFT 01:04:08.742 4.046545941382647 7




I want to join t1 and t2 side by side depending on ticker.

uj with ticker as key will not work as it interprets the key to be unique.

my final table should look like this

ticker time1 buyP vol time2 sellP vol2
GOOG 01:48:39 4.844727 5 05:50:50 6.430982 8
GOOG 04:59:17 1.53227 3 04:58:27 3.867353 3
GOOG 03:07:02 5.350923 9 01:23:46 8.355065 8
GOOG 04:56:25 4.57328 5
GOOG 00:24:52 4.861546 4
IBM 04:07:08 1.039343 7 02:31:11 0.366834 7
IBM 02:13:45 6.708738 5
IBM 01:06:16 6.789082 6
IBM 03:46:38 7.26781 3
MSFT 03:46:36 6.827999 2 05:31:58 4.12317 4
MSFT 02:06:39 0.080625 9 01:53:56 9.877844 1
MSFT 03:22:50 1.044512 6 01:04:09 4.046546 7
MSFT 06:28:41 3.380097 6


Thanks
Rajesh
2 REPLIES 2

wp
New Contributor

It's hard to infer a logic from your sample data.
The obvious way would be to join using aj and having tables ticker+time sorted.

WooiKent_Lee
New Contributor
One way:
 
ungroup((lj).`ticker xgroup/:(t1;t2))@\:'til each get max{exec count i by ticker from x}@'(t1;t2)