简体   繁体   English

当mysql版本为5.7.10时查询中的错误(在mysql 5.6.20中有效)

[英]Error in the query when the mysql version is 5.7.10 (it works in mysql 5.6.20)

I needed to migrate to another server host and the MySQL version is different. 我需要迁移到另一台服务器主机,并且MySQL版本有所不同。 I asked to change the version, but while this not happen my site return errors. 我要求更改版本,但这种情况没有发生,我的网站返回错误。

The main error is in this query: 主要错误在此查询中:

SELECT p.*
FROM product p INNER JOIN
     account a
     ON a.id = p.account_id INNER JOIN
     supplier s
     ON a.id = s.account_id
 WHERE p.status = 1 AND a.type = 'supplier' AND
       s.id IN (SELECT supplier_id FROM supplier_location WHERE location_id IN (SELECT _id FROM (SELECT @r AS _id, (SELECT @r := parent_id FROM location WHERE id = _id) AS parent_id FROM (SELECT @r := 3523) vars, location h WHERE @r <> 0) T1 ) ) AND
       p.name LIKE '%nira%'
ORDER BY p.category_id, p.account_id, p.name ASC

In MySQL 5.6.20 it works, but in MySQL 5.7.10 return this error: 在MySQL 5.6.20中可以使用,但在MySQL 5.7.10中返回以下错误:

Unknown column '_id' in 'where clause'

Someone knows how to fix? 有人知道如何解决?

Thanks. 谢谢。

There is a bug in mysql for that https://bugs.mysql.com/bug.php?id=79549 You should rewrite your query. mysql中存在一个有关https://bugs.mysql.com/bug.php?id=79549的错误,您应该重写查询。 Problem is in that_ID is an alias and those arent aprooved in where clausule. 问题在于that_ID是一个别名,而那些在子句中被拒绝。

You can fix it by changing 您可以通过更改来修复它

(SELECT @r := parent_id FROM location WHERE id = _id)

to

(SELECT @r := parent_id FROM location WHERE id = @r)

The modified query: 修改后的查询:

SELECT p.*
FROM product p INNER JOIN
     account a
     ON a.id = p.account_id INNER JOIN
     supplier s
     ON a.id = s.account_id
 WHERE p.status = 1 AND a.type = 'supplier' AND
       s.id IN (SELECT supplier_id FROM supplier_location WHERE location_id IN (SELECT _id FROM (SELECT @r AS _id, (SELECT @r := parent_id FROM location WHERE id = @r) AS parent_id FROM (SELECT @r := 3523) vars, location h WHERE @r <> 0) T1 ) ) AND
       p.name LIKE '%nira%'
ORDER BY p.category_id, p.account_id, p.name ASC

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

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