After working on that problem i figured out a solution with a little help and jsut wanted to share the solution to you.
$query = "SELECT sortb.value, sortb.field_id, sortc.value, sortc.field_id,
content.*, fieldvalues.* ";
FROM #__fields_values AS fieldvalues, #__content AS content
LEFT JOIN (#__fields_values AS ...
Looking at the source code for com_content - ArticlesModel does not have any filtering capabilities for custom fields. What it does have is tag filtering, so would it be possible to modify your code so that instead of writing a value to a custom field you instead assign a custom tag to the article which you can then use filter.tag when getting your ...
Your best bet would be to use joomla db to get all the rows and then use php array sorts to analyse and sort the result. Something like
$db = Factory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
$query->from('`#__content` AS content')...