How to exclude specified from all list of Multisite

I’d recommend using get_sites() instead of crafting $wpdb calls.

Add this code to your theme’s functions.php file.

function wpse365255_print_sites() {
    $args = array(
        'number' => 10000, // if you've got more than 10,000 sites, 
                           //you can increase this
        'public'        => 1,
        'spam'          => 0,
        'deleted'       => 0,
        'archived'      => 0,
        'site__not_in'  => array( 1, 2 ), 
        // this will exclude sites with ID 1 and 2
    );
    $sites = get_sites( $args ); // will return an array of WP_Site objects 
    $list="";
    foreach ( $sites as $site ) {
        $details = get_blog_details( $site->blog_id );
        if ( ! empty( $details ) ) {
            $list .= '<li>';
            $list .= '<a href="' . $details->siteurl . '">';
            $list .= $details->blogname;
            $list .= '</a>';
            $list .= '</li>';
        }
    }
    if ( ! empty( $list ) ) {
        echo '<ul>' . $list . '</ul>';
    }
}

Then, in your footer.php file, replace the code you originally posted with this:

<?php
    wpse365255_print_sites();
?>

It’s generally best to not define functions in template files, but instead put them in functions.php and call them from the template files, which is what this will do. (Better still to hook them to an action or filter hook, but that’s a lesson for another day.)

References