如何查询最大交易数…我的代码如下:
SELECT customer_id, COUNT(customer_id) FROM rental GROUP BY customer_id HAVING MAX(COUNT(customer_id)); //I need to get the MAXIMUM COUNT of the list
由于一个以上的客户可以拥有相同的最大数量,因此您应该执行以下操作
SELECT customer_id, COUNT(customer_id) AS customerrowcount FROM rental GROUP BY customer_id HAVING COUNT(customer_id) = (SELECT COUNT(customer_id) FROM rental GROUP BY customer_id ORDER BY COUNT(customer_id) DESC LIMIT 1)
但是,如果您可以选择任意客户,则应该使用rsbarro的答案