Sort tasks by deadline and those that do not have deadlines, sort them by schedule

To those who help in this forum, thank you very much.
I have a set of tasks, they all have a schedule, not all of them have an expiration date. I want to make a query that first shows the tasks with a due date, ordered from the closest to the farthest and then the tasks without a due date ordered by their scheduled from the oldest to the most recent @Siferiax @mentaloid

The following query shows me the tasks but not in the order I want:


{:title [:b "tasks"]
:query [:find (pull ?block [*])
:in $ ?start ?today

[?block :block/marker ?marker]
[?block :block/scheduled ?d]
[(>= ?d ?start)]
[(<   ?d ?today)]
[(contains? #{"LATER"} ?marker)]

:result-transform  (fn [result]
(sort-by  (fn [d]
(get d :block/deadline)) result ))

:inputs [:180d :today]
:breadcrumb-show? false 
:collapsed? false}


Should find your case among the multiple sorting variations in Sort deadline query chronologically.