How to get the distinct number of the nodes?
If you want to retrieve distinct number of the nodes of content type $type.
Try this.  



use Drupal\Core\Database\Database;

//- Retrieves a \Drupal\Core\Database\Connection which is a PDO instance
  $connection = Database::getConnection();
    $query = $connection->select('node', 'node')
        ->fields('node', array('nid'))
        ->condition('node.type', $type, '=')
        //- Force filtering of duplicate records in the result set.
         ->distinct()
        ->countQuery()
        ->execute();

    $count = $query->fetch(\PDO::FETCH_NUM);

 

Ps: you still have to add Your desired innerJoin to the query take a look to Select::innerJoin .