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:

#+BEGIN_QUERY

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

[?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}

#+END_QUERY

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