I am using a program called SQLfire to code and I'm not entirely sure what version we are using but I'm told it needs to work with SQL Server 2008.
Here is what I'm trying to do:
select CustomerNum, max(count(CustomerNum))
from Rentals
group by CustomerNum
I am aware that the question of how to properly implement max(count())
has already been answered multiple times, however, I have not found any way to solve it that works with SQLfire. So, I tried solving it using a correlated sub-query like so:
select CustomerNum, count(CustomerNum)
from Rentals R
group by CustomerNum
having count(CustomerNum) =
(select max(CustomerNum)
from Rentals
having count(CustomerNum) = count(R.CustomerNum))
but I found out that I have absolutely no idea what I'm doing. Is there a way to solve this problem using basic commands and sub-queries?
For reference, we are only using the column CustomerNum
(1000,1001,1002
etc) in table Rentals
. I am trying to find the customer whose CustomerNum
appears the most times in table Rentals
. I am thinking around using sub-queries to first count the number of times each customernum appears in the table, then find the customernum with the highest count.