Home › Forums › KX Academy › simplifying code using multiple fby possible? › Reply To: simplifying code using multiple fby possible?
-
t:([] payment_type:10#
CARD
CASH;vendor:10#a
bc
d`e;fare:10?50;tip:10?50)
t
payment_type vendor fare tip
----------------------------
CARD a 30 39
CASH b 17 0
CARD c 23 49
CASH d 44 46
CARD e 12 41
CASH a 2 18
CARD b 36 49
CASH c 37 40
CARD d 44 24
CASH e 28 13
select from t where ({exec (tip=max tip) and (fare>avg fare) from x};([] tip;fare)) fby vendor
payment_type vendor fare tip
----------------------------
CARD a 30 39
CARD b 36 49You can pass in sub tables to aggregate on more than one column
fby – Reference – kdb+ and q documentation – kdb+ and q documentation (kx.com)