Mysql 如何从订单明细表中检索最大产品id计数?
上面的查询不起作用。您试图按要聚合的列进行分组 试试这个:Mysql 如何从订单明细表中检索最大产品id计数?,mysql,sql,Mysql,Sql,上面的查询不起作用。您试图按要聚合的列进行分组 试试这个: select max(count(od_product_id)) as no from order_detail group by od_product_id 您可以为此使用HAVING select max(counted) from ( select od_product_id, count(*) as counted from order_detail group by od_product_id ) x1 我想通过以下方式
select max(count(od_product_id)) as no from order_detail group by od_product_id
您可以为此使用
HAVING
select max(counted)
from
(
select od_product_id, count(*) as counted
from order_detail
group by od_product_id
) x1
我想通过以下方式检索产品id和计数的产品id。。。描述限制1simpler@Strawberry可能是,我去了ANSI,但我想你肯定去了;-)上面的查询不起作用真的没有帮助。它显示了什么错误?我想同时检索product_id和counted product_id早期您没有阅读我的评论,您只是复制并粘贴了您之前的评论。MySQL说:文档#1111-组功能无效我想检索product_id和counted product_idboth@MyoMaMa你在开玩笑吧?
od\u product\u id
及其计数在结果中!您的查询中也没有产品id
。ohn。。对不起,我错了另一个max查询。现在我得到了太多。
SELECT od_product_id, COUNT(od_product_id) AS c
FROM order_detail
GROUP by od_product_id
HAVING count(od_product_id) >= ALL
(
SELECT count(od_product_id)
FROM order_detail
GROUP by od_product_id
)