create table tb(id int,name char)
insert into tb
select 1,'A' union all
select 6,'C' union all
select 5,'B' union all
select 2,'A' union all
select 7,'C' union all
select 3,'A' union all
select 8,'D' union all
select 4,'B'
select *,num=(select count(1) from tb where name=a.name)
from tb a order by num desc
drop table tb
insert into tb
select 1,'A' union all
select 6,'C' union all
select 5,'B' union all
select 2,'A' union all
select 7,'C' union all
select 3,'A' union all
select 8,'D' union all
select 4,'B'
select *,num=(select count(1) from tb where name=a.name)
from tb a order by num desc
drop table tb
id name num
----------- ---- -----------
1 A 3
2 A 3
3 A 3
7 C 2
4 B 2
5 B 2
6 C 2
8 D 1(所影响的行数为 8 行)
insert into tb
select 1,'A' union all
select 6,'C' union all
select 5,'B' union all
select 2,'A' union all
select 7,'C' union all
select 3,'A' union all
select 8,'D' union all
select 4,'B'
select *,num=(select count(1) from tb where name=a.name)
from tb a order by num desc,name
/*
id name num
----------- ---- -----------
1 A 3
2 A 3
3 A 3
4 B 2
5 B 2
6 C 2
7 C 2
8 D 1(所影响的行数为 8 行)
*/
drop table tb
select name, count(*) from 表
group by name order by count(*)
还有稳步的查不出来啊?
继续请教
wgsasd311(自强不息) ( )
他的应该可以满足你的要求
insert into tb
select 1,'A' union all
select 6,'C' union all
select 5,'B' union all
select 2,'A' union all
select 7,'C' union all
select 3,'A' union all
select 8,'D' union all
select 4,'B'select name,count(name) as num from tb group by name order by num desc
/*
name num
---- -----------
A 3
B 2
C 2
D 1(所影响的行数为 4 行)
*/
drop table tb