如何根据 mysql 中的另一个 table 排序结果

How to order result according to another table in mysql

我要select产品,以便根据另一个table的畅销产品。

select product_id
       from wp_product_details_fields
       where field in ( 'brand', 'model')
       group by product_id
       having  (  max(`field` = 'brand' and `value` = 'Intel') = 1 
                  OR
                  max(`field` = 'model' and `value` = 'Core i7') = 1  ) 
       order by (SELECT COUNT(*) AS magnitude 
                        FROM wp_order_items 
                        GROUP BY product_id 
                        ORDER BY magnitude DESC)

我遇到了这个错误:

MySQL said: Subquery returns more than 1 row

查询:

SELECT product_id
FROM (your complex query w/o ORDER BY) wpd
Left JOIN wp_order_items USING (product_id)
GROUP BY product_id
ORDER BY COUNT(*) /* DESC */