【问题标题】:Cannot use with in query不能在查询中使用 with
【发布时间】:2019-08-20 07:20:05
【问题描述】:

我有以下疑问:

with current_round as (
select * 
from match_case_1
where round_id = 12696
)
select *
from current_round cr
where
(
    not exists(select * from current_round where gameweek is null)
)
or 
(
    exists(select * from current_round where status = 1) 
    and not exists(select * from current_round where gameweek is not null)
    and cr.status = 1    
)
or 
(
    not exists(select * from current_round where status = 1)
    and not exists(select * from current_round where gameweek is not null)
    and cast(cr.`datetime` as date) = (
        select max(cast(`datetime` as date)) as `date`
        from current_round
        where status = 5 or status = 3
    )
);

这基本上适用于特定条件,请查看 here 了解更多详细信息,问题在于 PhpMyAdmin 似乎无法识别 with 运算符,事实上我明白了:

无法识别的语句类型。 (在位置 0 的“with”附近)

我能做什么?

【问题讨论】:

  • 这可能会解决你的问题[stackoverflow.com/questions/51759466/…
  • @SurajSingh 说找不到页面
  • @SurajSingh,它在小提琴中工作,因为您选择了 mysql 版本 8,但它在较低版本中不可用
  • @sfarzoso 。 . .如果您想使用 CTE,请升级到 MySQL 8+。
  • @GordonLinoff 我现在更新到最新版本的 MSQL,我得到:Error processing request Error code: 500 Error message: Internal Server Error 当我粘贴上面的查询时,PhpMyAdmin 返回此错误

标签: mysql sql phpmyadmin


【解决方案1】:

你可以试试下面 -

select * 
    from match_case_1
    where round_id = 12696 and not exists(select * from match_case_1 where gameweek is null)

【讨论】:

  • 应该current_roundmatch_case_1 还是别名?
  • @sfarzoso,它将是 match_case_1 ,我已经更新了 - 你现在可以查看
  • 我明白了,谢谢,但是如果您查看问题中的链接:stackoverflow.com/questions/55247116/… 完整查询可以访问 current_round 表这是一个临时表,我应该在 @987654326 附近使用别名吗@?我也更新了问题
【解决方案2】:

那是因为mysql中没有with操作符。

我能做什么?

使用有效的语法

【讨论】:

    猜你喜欢
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多