【发布时间】:2020-10-28 10:57:37
【问题描述】:
我在 join 中有一个子查询,我在其中使用 where 子句,但它给了我错误
找不到列:1054 'where 子句'中的未知列'products.id'
以下是我的查询:
Product::leftJoin(
'categories',
'products.category_id',
'=',
'categories.id'
)
->join('vendor_products', function ($join) {
$join->on(
'products.id',
'=',
'vendor_products.product_id'
)
})
->leftJoin('brand_products', function ($join) {
$join->on(
'products.id',
'=',
'brand_products.product_id'
)->on(
'brand_products.brand_id',
'=',
DB::raw('(
SELECT brand_id FROM
(SELECT brand_id, COUNT(brand_id) productCount
FROM brand_products
where brand_products.product_id = products.id
inner join brand on brand_products.brand_id = brand.id
GROUP BY brand_id order by productCount desc, DATE(brand.created_at) asc limit 1) as results)')
);
})
->get();
这是导致错误where brand_products.product_id = products.id的行。
任何帮助都将不胜感激。
【问题讨论】:
标签: php laravel laravel-query-builder