簡體   English   中英

laravel,如何使用所有值 select

[英]laravel, how to select with all values

如果 $property_values 中有任何 property_option_id,則 whereIn 返回 product_id。 如果它全部來自 $property_values,如何返回?

/*
arr int $property_values
 
db property_product_values
id, product_id, property_option_id
*/ 
    
$query->select('property_values.product_id')
                ->from('property_values')
                ->whereColumn('property_values.product_id', 'products.id')
                ->whereIn("property_values.property_option_id", $property_values);

如果product_idproperty_option_id沒有重復條目,此解決方案將返回具有所有屬性值的 product_id。

$query->select('property_values.product_id')
    ->from('property_values')
    ->whereIn('property_values.property_option_id', $property_values)
    ->groupBy('property_values.product_id')
    ->having(DB::raw('count(product_id)'), '>=', count($property_values))
    ->pluck('property_values.product_id');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM