Only return if greater than 0 (mysql count)

I have a Query with a count




if ($this->mode == "anzahl") {

          $query = Spieler::find();

          $query->joinWith(['abgeschlosseneTurniere' => function () {

          }]);

          $query->select(['spieler.*', 'COUNT(teilnehmer.id) AS playerCount'])

              ->where(["istInRangliste" => 1])

              //->andWhere(['>',"playerCount" , 0]);


          $query->groupBy(['spieler.id']);

          $query->orderBy(['playerCount' => SORT_DESC]);

          if (isset($this->limit)) {

              $query->limit($this->limit);

          }


          $models = $query->all();


      }

i cannot use the alias for my greater than 0 Condition.


//->andWhere(['>',"playerCount" , 0]);

any ideas how i can get only greater than 0 from my count?

thanky you

It’s because ‘playerCount’ is not defined until it is selected as ‘count(teilnehmer.id)’.

Consider using ‘having’.

Thank you!