select distinct userid,times from (select userid,count(userid) as times from table group by userid) where times<20 order by times desc
没调试,大概差不多,试试应该能用
select userid,count(userid) as times from table group by userid having count(userid)<20 order by userid
select UserID ,count(*)AS CISHU
from table
where SETTIME NOT NULL
GROUP BY USERID
ORDER BY USERID ASC
HAVING CISHU<20