Active users are those who logged in to their accounts for five or more consecutive days.
Write an SQL query to find the id and the name of active users.
답
SELECT
l1.id AS 'id'
,(SELECT a.name FROM Accounts a WHERE l1.id = a.id) AS 'name'
FROM Logins l1
JOIN Logins l2
ON l1.id = l2.id
AND DATEDIFF(l2.login_date, l1.login_date) BETWEEN 1 AND 4
GROUP BY l1.id, l1.login_date
HAVING COUNT(DISTINCT l2.login_date) = 4
;