1. 使用关联子查询
2. 使用时间interval
SELECT 审计表.COUNT, gspuser.code FROM gspuser JOIN ( SELECT gspaudit1912.userid, COUNT ( 1 ) FROM gspaudit1912 WHERE datetime > ( SELECT now() - INTERVAL ‘4 hour‘ ) GROUP BY userid ORDER BY 2 DESC ) 审计表 ON 审计表.userid = gspuser.ID ORDER BY 1 DESC
需要加强学习.. 自己的SQL 还是太弱鸡了.