Fix count with empty resultsets

Related to #1055