SQL语法错误多个计数

时间:2014-02-28 08:08:02

标签: mysql sql count sum

我遇到执行SQL查询的问题。这就是我的工作:

$sql = "SELECT
          SUM(PB = 1) AS PB,
          SUM(PG = 1) AS PG,
          SUM(PA = 1) AS PA,
          SUM(`Last Date Modified` < DATE_SUB(NOW(), INTERVAL 1 HOUR))
            AS LastDateModified,
        FROM `psttodo-uit`";

$result = $app['db']->executeQuery($sql);

$count = $result->fetchAll();

没有规则

  

SUM(Last Date Modified&lt; DATE_SUB(NOW(),INTERVAL 1 HOUR))AS LastDateModified,

它有效。这条规则有什么问题?

这是我的错误:

  

PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第6行的“FROM psttodo-uit”附近使用正确的语法

1 个答案:

答案 0 :(得分:2)

,声明

之前删除FROM
$sql = "SELECT
        SUM(PB = 1) AS PB,
        SUM(PG = 1) AS PG,
        SUM(PA = 1) AS PA,
        SUM(`Last Date Modified` < DATE_SUB(NOW(), INTERVAL 1 HOUR)) AS LastDateModified
        FROM `psttodo-uit`";