Accessing full dataframe after a join within a Query.jl query

I don’t think this can be done in one query, and your three query version is almost certainly the most efficient way to do this.

Your line that starts with @let negcontrol = @from l in k begin will certainly not work: k is the new range variable that will refer to the current row, so using k as the source for another query won’t work. A query of this form:

@from i in X begin
@select i into k
...

will be rewritten as

temp1 = @from i in X begin
    @select i
end
@from k in temp1 begin 
...
end