DATEADD在我的查询中不起作用

时间:2014-08-28 12:07:17

标签: php mysql sql

我遇到了问题,我无法找到解决方案。使用之前提出的问题(SELECT rows with time 30 minutes or less?)我尝试使我的COUNT(*)函数正常工作,但我无法使其工作。有人有想法吗?

$adViewUnique = $dbh->query('SELECT COUNT(*) FROM g_ad_view WHERE ad_view_time >= DATEADD(mi, -30, GETDATE())')->fetchColumn();

这是我回来的错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1305 FUNCTION 18RVS15.DATEADD does not exist' in /var/www/vhosts/revulsionfm.com/RVS2.0/widgets/advertisement.php:38 Stack trace: #0 /var/www/vhosts/revulsionfm.com/RVS2.0/widgets/advertisement.php(38): PDO->query('SELECT COUNT(*)...') #1 {main} thrown in /var/www/vhosts/revulsionfm.com/RVS2.0/widgets/advertisement.php on line 38

3 个答案:

答案 0 :(得分:17)

MySQL语法为:

WHERE ad_view_time >= now() - interval 30 minute

答案 1 :(得分:9)

DateAdd拼写错误:必须是DATE_ADD(带下划线)。请参阅documentation

答案 2 :(得分:0)

您可以使用DATE_SUB(CURDATE(),间隔30分钟)