2016-02-12 116 views
1

下面的查询在旧版本的MySQL上工作(不记得是哪一个)。升级MySQL后查询不起作用

SELECT @r AS _id, 
     (
     SELECT @r := parent 
     FROM t_hierarchy 
     WHERE id = _id 
     ) AS parent, 
     @l := @l + 1 AS lvl 
FROM (
     SELECT @r := 1218, 
       @l := 0, 
       @cl := 0 
     ) vars, 
     t_hierarchy h 
WHERE @r <> 0 

自从我升级到5.7,我得到的错误:

Unknown column '_id' in 'where clause'

帮助的人?

+0

可能重新开始,与设置的采样数据和预期的结果 – Strawberry

+0

请粘贴表结构t_hierarchy的别名 – Sandy

回答

0

似乎WHERE条件不允许为MySQL 5.7

An alias can be used in a query select list to give a column a different name. You can use the alias in GROUP BY, ORDER BY, or HAVING clauses to refer to the column:

Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.

请参阅相关的文档http://dev.mysql.com/doc/refman/5.7/en/problems-with-alias.html