Is there a way to order by COUNT('column') without returning an integer?
Try this :



  use Drupal\Core\Database\Database;
  $connection = Database::getConnection();
  $sth = $connection->select('eventform', 'm');
  $sth->addField('m', 'event');
  $sth->addExpression('COUNT(m.event)', 'count');
  $sth->groupBy('m.event');
  $sth->orderBy('count','DESC');
  //- Execute the statement
  $data = $sth->execute();
  //- Get all the results
  $results = $data->fetchAll(PDO::FETCH_ASSOC);



you will get the $results as an array something like:



array:5 [▼
   0 => array:2 [▼
     "event" => "Brewery"
     "count" => "10"
   ]
   1 => array:2 [▼
     "event" => "Conference"
     "count" => "8"
   ]
   2 => array:2 [▼
     "event" => "Concert"
     "count" => "7"
   ]
   3 => array:2 [▼
     "event" => "Dinner"
     "count" => "6"
   ]
   4 => array:2 [▼
     "event" => "Musical"
     "count" => "4"
   ]
 ]



if you want to get only the event name loop thought the $results something like :



 $events_name = [];
 foreach ($results as $result){
    $events_name[] = $result['event'];
  }