Hai il risultato giusto in entrambi gli esempi.
Se usi solo count in select hai sempre un numero come risultato della query. Quindi il tuo risultato dal database è prevedibile.
Nel caso di Rails, stai cercando di ottenere una serie di record per scope con count nella dichiarazione select. È prevedibile un set vuoto se hai count nella tua richiesta.
Prova count_by_sql metodo https://apidock.com/rails/ActiveRecord/Base/count_by_sql/class per ottenere il numero di record anziché il set vuoto.
E usalo senza scopo, ma con il metodo di classe:
def self.unverified_with_no_associations()
self.count_by_sql("SELECT COUNT(DISTINCT(accounts.id, accounts.email)) FROM accounts WHERE level = 0 AND id NOT IN
(SELECT DISTINCT(account_id) FROM verifications) AND id NOT IN
(SELECT DISTINCT(account_id) FROM positions) AND id NOT IN
(SELECT DISTINCT(account_id) FROM edits) AND id NOT IN
(SELECT DISTINCT(account_id) FROM posts) AND id NOT IN
(SELECT DISTINCT(account_id) FROM reviews) AND id NOT IN
(SELECT DISTINCT(sender_id) FROM kudos) AND id NOT IN
(SELECT DISTINCT(account_id) FROM stacks WHERE account_id IS NOT NULL)")
end