I prefer more raw data in the database than the approach that @Matt H protects. Create a table that writes all logins to the site (or, if you want, new session sessions) along with its time and date:
CREATE TABLE LoginLog (
UserId INT NOT NULL REFERENCES Users (UserId),
LoginTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)
CREATE INDEX IX_LoginLog USING BTREE ON LoginLog (UserId ASC, LoginTime DESC)
UserId . , , , , .
, :
SELECT COUNT(*)
FROM (SELECT DATE(log.LoginTime) AS LoginDate,
COUNT(*) AS LoginCount
FROM LoginLog log
WHERE log.LoginTime >= DATE(DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 30 DAYS))
GROUP BY LoginDate
HAVING COUNT(*) > 0) a
30, .
, MySQL ( SQL Server PostgreSQL), , , . , .