SELECT COUNT(userId) 'users logged in more than three times:' FROM (SELECT DISTINCT(userId) AS 'userId' FROM i_user_login_logs GROUP BY userId HAVING COUNT(login_date) > 3) distinctUser;