mysql - How to order result according to another table in mysql
问题描述
I want to select products in order to best selling items according to another 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)
I've got this Error:
MySQL said: Subquery returns more than 1 row
解决方案
The query:
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 */
推荐阅读
- asp.net - ASP.NET MVC 未处理 OpenIdConnect signin-oidc 路由
- java - 如何使用修复 HBox 内 TOP_LEFT 上的菜单按钮
- docker - 如何使用融合的 docker 图像设置 kafka 集群
- python - 使用 pandas 根据特定列中的条件替换日期值
- java - 如何在 Spring 运行时从文本文件中重新加载数据
- react-native - 使用 ReactNative 和 StyledComponents 布局子组件
- java - AWS:Lambda 函数应该用哪种语言编写,以便 lambda 可以访问/调用 .so 文件(linux 中的动态库)
- gmail - 如何将别名电子邮件添加到我的新帐户?
- android - 在片段事务中获取异常作为已调用的提交
- postgresql - SQLSTATE 和 GET STACKED DIAGNOSTICS 信息在另一个函数中?