无法理解此SQL有什么问题。
我认为它以前可以在MySQL上运行。 无论如何,它现在不适用于MariaDB。
表如下:
MariaDB [piHeatingDB]> SELECT * FROM powerLog LIMIT 4;
+----+---------------------+-----------+-----------+-----------+------------------+------------------+------------------+--------+-------+
| id | ts | currentR1 | currentS2 | currentT3 | currentAverageR1 | currentAverageS2 | currentAverageT3 | pulses | event |
+----+---------------------+-----------+-----------+-----------+------------------+------------------+------------------+--------+-------+
| 1 | 2020-03-15 16:28:10 | 0.97 | 0.08 | 0.94 | 0.87 | 0.08 | 0.84 | 0 | cron |
| 2 | 2020-03-15 16:30:09 | 0.93 | 0.07 | 0.91 | 0.87 | 0.08 | 0.84 | 0 | cron |
| 3 | 2020-03-15 16:32:38 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | cron |
| 4 | 2020-03-15 16:34:22 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | cron |
+----+---------------------+-----------+-----------+-----------+------------------+------------------+------------------+--------+-------+
4 rows in set (0.009 sec)
这是错误的SQL:
SELECT
currentAverageR1,
currentAverageS2,
currentAverageT3,
FROM
powerLog
WHERE
ts > DATE_SUB(
'2020-03-15 18:30:03', INTERVAL 1 MINUTE
)
AND ts < DATE_ADD(
'2020-03-15 18:30:03', INTERVAL 1 MINUTE
)
LIMIT
1
这给了我
MariaDB [piHeatingDB]> SELECT
-> currentAverageR1,
-> currentAverageS2,
-> currentAverageT3,
-> FROM
-> powerLog
-> WHERE
-> ts > DATE_SUB(
-> '2020-03-15 18:30:03', INTERVAL 1 MINUTE
-> )
-> AND ts < DATE_ADD(
-> '2020-03-15 18:30:03', INTERVAL 1 MINUTE
-> )
-> LIMIT
-> 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near 'FROM
powerLog
WHERE
ts > DATE_SUB(
'2020-03-15 18:30:03', INTERVAL 1 ' at line 5
我可能只是愚蠢,但是...
谢谢 / jon
答案 0 :(得分:1)
好像您在FROM
语句之前可能会有一个逗号
SELECT
currentAverageR1,
currentAverageS2,
currentAverageT3, <-----
FROM