Yes, it is legit. The code would look like:
select x.*
from x
where (select count(. . .) from . . .) >= (select count( . . . ) from . . . );
The parentheses around the subqueries are necessary. A group by
would not be appropriate in the subqueries, because the subqueries could then return more than one row. If either returns zero rows, then no rows will be returned, because the value used for the comparison is NULL
.
That said, this would be an unusual construct. I would recommend that you ask another question with sample data and desired results to see if there are alternative ways to write the query.