Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试查找上周内加入网站的用户子集
该表是users并且日期字段(dateadded)是 unix 时间戳,例如2012-04-29 17:31:57
users
dateadded
2012-04-29 17:31:57
这是我正在尝试的,但它会返回所有用户:
SELECT * FROM users WHERE dateadded <= NOW() AND dateadded >= DATE_SUB(dateadded, INTERVAL 7 DAY)
你有错误的条件。你想要now()两个比较:
now()
SELECT * FROM users WHERE dateadded <= NOW() AND dateadded >= DATE_SUB(now(), INTERVAL 7 DAY)