Thanks SO MUCH to Nic, I finally found the solution with a CASE instead of an IF!
$query = $this
->createQueryBuilder( 'a' )
->select('a')
->add('from', 'path\to\whatever\table a')
->addSelect('CASE WHEN a.ranking IS NULL THEN 9999 ELSE a.ranking END as HIDDEN ORD')
->where( 'a.deleted IS NULL' )
->orderBy( 'ORD', 'asc' )
->getQuery()
;