That looks quite a neat solution. Thanks.
One possible problem I can see, though, is that I was hoping to use this query as a view, which would greatly simplify the main query, but I was reading on the MySql help site that views don't allow sub-queries in the From clause.
Is there a way that I could encapsulate this query, so I could call it from the From clause of the main query, which would do the range comparisons of the degree columns with the input parameters, hence a table would need to be returned, rather than a variable from a procedure?
Again, given the complexity of what you are doing, I'd be sorely tempted to use a stored procedure that would put your results into a TEMPORARY TABLE. So you would call the procedure and then use your own code to JOIN to the temp table created by the procedure.
So long as this is all done on the same open connection, the temporary table will (a) be only visible on that connection and (b) remain available until you drop it or until the connection is closed.