simplifying code using multiple fby possible?

https://learninghub.kx.com/forums/topic/simplifying-code-using-multiple-fby-possible

I want to simplify the code below into single line using two fbys but it doesn't working.

Is there any possible way to do it? or should I just keep using separate queries?


tip_stat : select avg tip by payment_type from jan09 where fare > (avg;fare) fby vendor

select payment_type, tip from tip_stat where tip = max tip

t:([] payment_type:10#CARDCASH;vendor:10#abcd`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 49

You can pass in sub tables to aggregate on more than one column

fby – Reference – kdb+ and q documentation - kdb+ and q documentation (kx.com)