There probably is some room to clean up the first of the two queries to make that a bit more clear. That might be a useful step toward getting to an understandable 1 query solution and it would give the planner less work to do.
Author of Typica software for coffee roasters.