0

I am wanting to list names and the number of times they have done a certain action. I then want to order the names by the most amount of times.

I have the below code so far but I keep getting errors:

select name, count(*) as NoOfTimes
from CustName
group by count(*);
order by count(*) asc;
1
  • 2
    You have an extra semicolon before the order by. This seems like a simple typographical error to me. Commented Dec 29, 2016 at 3:17

3 Answers 3

1

I should note that if you want the most times at the beginning of the result set, the you want a descending sort:

select name, count(*) as NoOfTimes
from CustName
group by name
order by count(*) desc;
Sign up to request clarification or add additional context in comments.

Comments

1

In order to show count by name, you must group by name

select name, count(*) as NoOfTimes
from CustName
group by name
order by NoOfTimes desc

Comments

0

Order by index also a good idea:

select name, count(*) as NoOfTimes
from CustName
group by name
order by 2 DESC

Comments

Your Answer

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.