mysql,介于和限制之间

时间:2012-07-24 12:17:01

标签: php sql mysqli

我想获取某个日期间隔之间的所有行,结果集最多为50条记录。什么可以查询?我不断收到错误:

$sql = "SELECT DISTINCT userId FROM ".$TableName.
       " where time BETWEEN (NOW() - INTERVAL "
       .$USER_COUNT_DURATION.
       " MINUTE AND NOW())  LIMIT 0, ".$limit." ;";

1 个答案:

答案 0 :(得分:1)

看起来像括号问题。 “MINUTE AND NOW())”应该是“MINUTE”和NOW()“

$sql = "SELECT DISTINCT userId FROM ".$TableName." where time BETWEEN (NOW() - INTERVAL ".$USER_COUNT_DURATION." MINUTE) AND NOW() LIMIT 0, ".$limit." ;";