使用函数的SQL查询-如何获取列表的最大数量 [英] SQL Query of Using Functions - How to get MAXIMUM Count of the list

查看:58
本文介绍了使用函数的SQL查询-如何获取列表的最大数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查询最大交易笔数... 我的代码如下:

How can I query for the MAXIMUM COUNT Number of transaction... My code is as follows:

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

推荐答案

由于一个以上的客户可以拥有相同的最大数量",因此您应该执行以下操作

Since more than one customer can have the same Maximum of the count you should do as follows

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的答案

However if you're ok with an arbitrary customer being selected than you should use rsbarro's answer

这篇关于使用函数的SQL查询-如何获取列表的最大数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆