2016-02-12 151 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