MYSQL语法错误,日期时间为

时间:2017-01-12 14:39:50

标签: mysql

我目前正在将我的API从SQL转换为MySQL,但是我的一个查询在下面的这一点上失败了。

查询:

SELECT u.DATETIME,
       SUM(Value * m.Multiplier) * 1 AS Usage,
       TIMESTAMPDIFF(SECOND, '1970-01-01 00:00:00', UNIX_TIMESTAMP(u.DATETIME)) as Datestamp_epoch 
FROM MeterMaps m
JOIN UsageElectricityDaily u ON m.ChanID = u.ChanID
JOIN SourceChannels c ON c.ChanID = m.ChanID
WHERE m.LocationID = 1
      AND c.QuantityID = 'Usage'
      AND u.DateStamp >= '01/12/2016 00:00:00'
      AND u.DateStamp < '31/12/2016 00:00:00'
      AND m.Utility = 'Electric'
GROUP BY u.Datestamp

引发的错误是

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   'Usage,TIMESTAMPDIFF(SECOND,'1970-01-01 00:00:00'附近,'   第1行的UNIX_TIMESTAMP(u.DATETIME))'

1 个答案:

答案 0 :(得分:0)

在MySQL中,单词usagekeyword,因此必须用反引号括起来或更改它。

SELECT u.DATETIME,
       SUM(Value * m.Multiplier) * 1 AS `Usage`
...