该查询取所有降价幅度超过30%的产品:
return $query->where([
'Products.reduced_price / Products.price <' => 0.7,
]);此查询将导致以下错误:
Column not found: 1054 Unknown column 'products.price' in 'where clause'为什么表别名被转换为小写?这个错误似乎取决于你的mysql设置。一些设置似乎不区分大小写(例如,我的dev-machine),其他设置,比如我的生产服务器,是区分大小写的;)
遗憾的是,在这种情况下不能省略表别名"Products“,因为有一个连接表也有一个名为"price”的列。省略别名将导致此错误:Column 'price' in where clause is ambiguous
发布于 2020-06-24 17:43:08
原因是QueryExpression类的_parseCondition方法。它将假定第一个空格之后的所有内容都是运算符,并对其使用strtolower,从而使别名变得小写。
这可以通过删除表达式中的所有空格来轻松缓解,如下所示:
return $query->where([
'Products.reduced_price/Products.price <' => 0.7,
]);https://stackoverflow.com/questions/62552112
复制相似问题