高手帮忙看个查询问题.....急
假如有表A
列1 列2
1 A
2 A
3 B
4 C
5 B
6 A
怎样查询出出现最多列2值的结果
查询结果为:
A
B
C
[解决办法]
select 列2 from 表A group by 列2 order by count(*) desc
[解决办法]
小楼是对的。证明:
create table t(
Col1 int,
Col2 varchar(10))
insert t select 1, 'A '
union all select 2, 'A '
union all select 3, 'B '
union all select 4, 'C '
union all select 5, 'B '
union all select 6, 'A '
--select * from t
select Col2 from t group by Col2 order by count(*) desc
drop table t
--结果:
/*
Col2
----------
A
B
C
*/
[解决办法]
假如有表A
列1 列2
1 A
2 A
3 B
4 C
5 B
6 A
怎样查询出出现最多列2值的结果
select 列2 , count(*) cnt from tb group by 列2 order b cnt desc