如何从当前日期检索用户最近 30 天的记录
How to retrieve the last 30 days records for a user from current date
我是 mysql 的新手,我想构建一个查询来检索特定 user_id 的最近 30 天记录。这是下面的示例 table,我对它有什么帮助有点难过吗?
transaction_id | user_id | activities_id | time,
4 | 19 | 1 | 2015-04-06 14:44:35
5 | 19 | 6 | 2015-04-06 14:45:27
另请找到我的 table 格式如下:
transaction_id: 'int(10) unsigned','NO','PRI',NULL,'auto_increment'
user_id: 'int(10) unsigned','YES','MUL',NULL,''
activities_id: 'int(10) unsigned','YES','',NULL,''
time: 'datetime','YES','',NULL,''
你需要这样的东西:
SELECT * FROM table
WHERE time BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
你可以试试这个。
select * 来自 table i where i.time <= now() and i.timesta >=date_sub(now(), interval 7日)
and w.timestamp <= now() and w.timestamp >= date_sub(now(), interval 7 day);
我是 mysql 的新手,我想构建一个查询来检索特定 user_id 的最近 30 天记录。这是下面的示例 table,我对它有什么帮助有点难过吗?
transaction_id | user_id | activities_id | time,
4 | 19 | 1 | 2015-04-06 14:44:35
5 | 19 | 6 | 2015-04-06 14:45:27
另请找到我的 table 格式如下:
transaction_id: 'int(10) unsigned','NO','PRI',NULL,'auto_increment'
user_id: 'int(10) unsigned','YES','MUL',NULL,''
activities_id: 'int(10) unsigned','YES','',NULL,''
time: 'datetime','YES','',NULL,''
你需要这样的东西:
SELECT * FROM table
WHERE time BETWEEN NOW() - INTERVAL 30 DAY AND NOW()
你可以试试这个。
select * 来自 table i where i.time <= now() and i.timesta >=date_sub(now(), interval 7日) and w.timestamp <= now() and w.timestamp >= date_sub(now(), interval 7 day);