I would like to convert the following query into a single query
tab:([price:til 10]side:10?-1 1;qty:990 + 2 * til 10);
a:select[>price] from tab where side=1;
b:select from a where sums[qty] <= max(min[sums qty];100);
or
select from (select[>price] from tab where side=1) where sums[qty] <= max(min[sums qty];100);
I have tried to implement a select statement using fby as follows:
select from tab where side=-1, ({sy:sums[y]; sy<=max(min[sy];x)}[100];qty) fby side
However this doesn't sort the table tab
correctly i.e. according to >price
.
I suppose one could pre sort the table i.e.
select from `price xasc tab ...
However this would seem a computationally inefficient solution. Could some wise Q God please advise me on how to most efficiently achieve this. Thanks, Best Regards