2

I find that I need to apply an aggregate a lot, but I don't want to show the aggregated value as well. So the best way to do this was to just nest the query to filter it out (like below) but there has to be a better way, how?

select state
from(
 select state, max(cnt)
 from (
 select state, count(*) as cnt
 from customer
 group by state) as t
) as r;

Here I just want to show state without the max value.

asked Nov 24, 2016 at 22:32
3
  • 1
    You want the state with the max count? What is there are two (or more) with the same max count? Commented Nov 24, 2016 at 23:03
  • @ypercubeTM it will take one of them I guess? It doesn't matter. Commented Nov 24, 2016 at 23:07
  • I said it (the result) doesn't matter, I guessed the behavior. @ypercubeTM Commented Nov 24, 2016 at 23:14

1 Answer 1

4

I think you can achieve this result without so many subqueries:

Select State
 From Customer
 Group By State
 Order By Count(*) Desc
 Limit 1;
answered Nov 24, 2016 at 22:51
1
  • Nice to know it's possible to limit the query. Commented Nov 24, 2016 at 23:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.