我想列出名字和他们完成某项行动的次数。然后我想要最多次订购这些名字。
到目前为止,我有以下代码,但我一直收到错误:
select name, count(*) as NoOfTimes
from CustName
group by count(*);
order by count(*) asc;
答案 0 :(得分:1)
我应该注意,如果你想在结果集的开头有大多数次,你想要一个降序排序:
select name, count(*) as NoOfTimes
from CustName
group by name
order by count(*) desc;
答案 1 :(得分:1)
要按名称显示计数,您必须按名称分组
select name, count(*) as NoOfTimes
from CustName
group by name
order by NoOfTimes desc
答案 2 :(得分:0)
按索引排序也是一个好主意:
select name, count(*) as NoOfTimes
from CustName
group by name
order by 2 DESC