SELECT ROUND(COUNT(l.user_id)/COUNT(*),3) AS P FROM login l RIGHT JOIN( SELECT user_id, MIN(date) AS first_login FROM login GROUP BY user_id ) AS t ON l.user_id=t.user_id AND l.date+0=t.first_login+1; 看了好多大家的写法,都是分好多步这里用一个子查询,`RIGHT JOIN` 配合 `COUTN(ID)/COUNT(*)` 的写法一步到位