You can do it using filters on the query:
The filters can go in functions.php or in the template ahead of the query (I would put them in the template at least while testing).
function mam_posts_fields ($fields) {
global $mam_global_fields;
if ($mam_global_fields) $fields .= ", $mam_global_fields";
return $fields;
}
function mam_posts_join ($join) {
global $mam_global_join;
if ($mam_global_join) $join .= " $mam_global_join";
return $join;
}
function mam_posts_orderby ($orderby) {
global $mam_global_orderby;
if ($mam_global_orderby) $orderby = $mam_global_orderby;
return $orderby;
}
add_filter('posts_fields','mam_posts_fields');
add_filter('posts_join','mam_posts_join');
add_filter('posts_orderby','mam_posts_orderby');
This part has to go in the template:
$mam_global_fields = 'SUM(metaA.meta_value, metaB.meta_value) as meta_sum';
$mam_global_join = "JOIN $wpdb->postmeta metaA ON (metaA.post_id = $wpdb->posts.ID AND metaA.meta_key = 'metaA')
JOIN $wpdb->postmeta metaB ON (metaB.post_id = $wpdb->posts.ID AND metaB.meta_key = 'metaB')";
$mam_global_orderby = " meta_sum ASC";
// Your query_posts goes here