日期:2014-05-18  浏览次数:20407 次

如何得出列中那个字段对多
SQL code


create table table1(a varchar(2));
insert into table1 select 'h'
insert into table1 select 'a'
insert into table1 select 'b'
insert into table1 select 'b'
insert into table1 select 'c'
insert into table1 select 'c'
insert into table1 select 'a'
insert into table1 select 'd'
insert into table1 select 'd'
insert into table1 select 'd'
insert into table1 select 'a'
.....
select a from table1;
drop table table1;



如何得出列中那个字段对多

------解决方案--------------------
探讨
SQL code


create table table1(a varchar(2));
insert into table1 select 'h'
insert into table1 select 'a'
insert into table1 select 'b'
insert into table1 select 'b'
insert into table1 select 'c'
ins……

------解决方案--------------------
SQL code

select *,count(*) as total from table1 group by a
having count(*)=(select max(total) from(select *,count(a) as total from table1 group by a)t)

--a,d一样多
-----------
a    total
---- -----------
a    3
d    3