Fix count method to work with select statement.

fix_count_with_select_statement (#372) (edariedl)