读书人

怎么得出列中那个字段对多

发布时间: 2012-05-06 16:15:43 作者: rapoo

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

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 ahaving count(*)=(select max(total) from(select *,count(a) as total from table1 group by a)t)--a,d一样多-----------a    total---- -----------a    3d    3 

读书人网 >SQL Server

热点推荐