MYSQL last login and number of logins in last 3 months
问题 I'm trying to write a query to join a user table to an activity logging table and return the following for each user: A) The time they last logged in. B) The number of logins in the last 3 months. This is what I have come up with so far: SELECT A.UserID, COUNT( Activity ) AS Logins, MAX( TIME ) AS LastLogin FROM UserMaster A LEFT JOIN UserWebActivity B ON A.UserID = B.UserID AND Activity = 'Login' AND TIME BETWEEN DATE_SUB( NOW( ) , INTERVAL 3 MONTH ) AND NOW( ) GROUP BY A.UserID This almost