How to return count of custom post type posts with a specific custom field value via $wpdb?

While custom SQL is sometimes what it takes, note that to address your concern for WP_Query it supports 'fields' => 'ids' argument to limit data returned to IDs (which can be easily used for count).

In many cases that is reasonably efficient while more robust and future-proof in WP environment.