It looks like you ran that in the data explorer. For the custom SQL badges you would need to turn on the hidden site setting and add the query to the badge page:
However, not everyone can do that depending on their hosting package.
But a data explorer one is more than possible too if you can’t have the custom SQL triggered ones. I think you’d have to make some choices about how often you ran it, and how the Badges would be awarded from the results (manually one by one, or through the bulk award), but it’s definitely do-able.
Something simple may be better, though you perhaps want to add a date range parameter too?
WITH foo AS (SELECT ub.user_id,count(ub.user_id), max(ub.granted_at) granted_at
FROM user_badges ub
WHERE ub.badge_id=108
GROUP BY ub.user_id)
SELECT user_id, granted_at
FROM foo
WHERE count >4
ORDER BY granted_at DESC