WP_query exclude a category unless it has more than one catagory

I end up with this to exclude the mama category:

/**
 * filter home and blog pages for mama category
 * exclude posts that have that category unless they have more categories
 * @param string $where
 * @return string
 */
function filter_mama_cat( $where) {
    // get the term to exclude
    $term = get_term_by('slug', 'mama', 'category');
    // only on home and blog pages
    if ( is_home() || is_front_page() ) {
        $where .= 'AND (
        wp_posts.ID NOT IN (
            SELECT object_id
            FROM wp_term_relationships
            WHERE term_taxonomy_id IN (' . $term->term_taxonomy_id. ')
        )
        OR 1 <
        (   SELECT count(*) AS "count"
            FROM wp_term_relationships
            JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id
            WHERE wp_term_taxonomy.taxonomy = "category" AND wp_term_relationships.object_id = wp_posts.ID
            GROUP BY wp_term_relationships.object_id
        )
    )';
    }
    return $where;
}
add_filter( 'posts_where', 'filter_mama_cat');

For theme purposes use it in functions.php.