Given an array reference of tree nodes that have been selected by the user, traverses the tree and returns the equivalent SQL query and a list of hashes representing the "clauses" select option list. Each has contains the keys TEXT, INDEX, SELECTED, and DEPTH. TEXT is the displayed text of the option (including parentheses, not including indentation); INDEX is the 0-based index of the option in the list (also used as its CGI parameter); SELECTED is either 'SELECTED' or '', depending on whether the node corresponding to the select option was in the SELECTED_NODES list; and DEPTH is the level of indentation for the option.