select uid, count(distinct login_date) as days, count(id) as times from user_login_tb group by uid having datediff((select max(login_date) from user_login_tb),max(login_date))>29 and count(id)>2

select uid, count(distinct login_date) as days, count(id) as times from user_login_tb group by uid having datediff((select max(login_date) from user_login_tb),max(login_date))>29 and count(id)>2