Welcome.
- Try the following:
#+BEGIN_QUERY {:title "Test" :query [ :find (pull ?h [*]) :in $ % :where [?h :block/marker ?marker] [(contains? #{"TODO"} ?marker)] (not (get-parent ?parent ?h) [?parent :block/marker ?pm] [(contains? #{"DOING"} ?pm)] ) ] :rules [ [(get-parent ?parent ?child) [?child :block/parent ?parent] ] [(get-parent ?parent ?child) [?t :block/parent ?parent] (get-parent ?t ?child) ] ] :remove-block-children? false } #+END_QUERY
- For better understanding, I would suggest renaming your rule to
ancestor
, like in this post.