我正在尝试从 MySQL 表中选择 1 到 2 周大的记录该表有一个日期列。有一个 10 天前的日期,但查询忽略了它。你能帮忙吗?这是我正在使用的查询:
$week2 = mysql_query("SELECT * FROM apps WHERE (user = '"
.mysql_real_escape_string($_POST['username']) . "') and date BETWEEN ( DATE_SUB( NOW(),
INTERVAL 2 WEEK), DATE_SUB( NOW(), INTERVAL 1 WEEK )");
如果我将日期设置为不到一周,我可以选择没有问题的记录:
$week1 = mysql_query("SELECT * FROM apps WHERE (user = '" .
mysql_real_escape_string($_POST['username']) . "') and date > NOW() - INTERVAL 1 WEEK
ORDER BY id DESC limit 1");