简体   繁体   English

MySQL 上的 WITH 语句语法错误 1064

[英]WITH statement on MySQL syntax error 1064

I am trying to use a WITH statement so that I can use the sum of 2 columns later on but I keep getting hit with an ERROR 1064 (42000): You have an error in your SQL syntax我正在尝试使用 WITH 语句,以便稍后可以使用 2 列的总和,但我一直受到ERROR 1064 (42000) 的影响:您的 SQL 语法有错误

I fiddled around with different ways of using the statement with no success so I am starting to think that it's perhaps because of my MySQL version (select @@version says its '5.7.38-0ubuntu0.18.04.1').我摆弄了使用该语句的不同方式但没有成功,所以我开始认为这可能是因为我的 MySQL 版本(选择@@version 说它的'5.7.38-0ubuntu0.18.04.1')。

My command:我的命令:

WITH timings AS (
SELECT id, timestart, timestart+timeduration AS timeend FROM events WHERE userid = 1000
)
SELECT * FROM timings WHERE timeend > ...

Could someone perhaps enlighten me on my mistaken or perhaps give me an alternative for the handling of a sum of columns.有人可以告诉我我的错误,或者给我一个替代方法来处理列的总和。 Thank you in advance.先感谢您。

Common Table Expressions (aka CTE or With s) were introduced in Mysql 8. So yes, you either update your DB engine (I'd recommend that) or rewrite your CTE as a subquery:公用表表达式(又名CTEWith s)在 Mysql 8 中引入。所以是的,您要么更新数据库引擎(我建议这样做),要么将 CTE 重写为子查询:

SELECT 
    * 
FROM (
    SELECT 
        id, 
        timestart, 
        timestart+timeduration AS timeend 
    FROM events 
    WHERE userid = 1000
) timings 
WHERE timeend > ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM