语法错误意外

时间:2016-08-18 17:15:04

标签: sql mysql-error-1064

with ntable (date,pnodeid,rtavg)
   as
    ( 
      select date,pnodeid, (select avg(myaverage) from (values (hour8),(hour9),(hour10),(hour11),(hour12),(hour13),(hour14),(hour15),(hour16),(hour17),(hour18),(hour19),(hour20),(hour21),(hour22),(hour23)) as TblAverage(myaverage)) from pjm_realtime 
     )
 select date,rtavg  
from ntable
where rtavg > 65 and pnodeid = '51288' and weekday(date) between 0 and 4 and year(date) >= '2014';

我收到1064错误。尝试获取多列的平均值并将其用作搜索条件

2 个答案:

答案 0 :(得分:0)

MySQL没有CTE / WITH;但是,您可以简单地使用子查询:

select date, rtavg  
from
( 
  select date, pnodeid, (select avg(myaverage) from (values (hour8),(hour9),(hour10),(hour11),(hour12),(hour13),(hour14),(hour15),(hour16),(hour17),(hour18),(hour19),(hour20),(hour21),(hour22),(hour23)) as TblAverage(myaverage)) rtavg from pjm_realtime 
) btable
where rtavg > 65 and pnodeid = '51288' and weekday(date) between 0 and 4 and year(date) >= '2014';

答案 1 :(得分:0)

WITH语法是MySQL不支持的SQL-99的一个特性。

我在这里写到了这个缺乏功能:WITHer Recursive Queries?

2016年4月,我参加了一个由MySQL开发人员组成的小组的演讲,他们表示他们打算在下一个主要版本MySQL 8中支持WITH语法。但这可能不会成功。准备好几年。