首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-05-06 
如何得出列中那个字段对多SQL codecreate table table1(a varchar(2))insert into table1 select hinse

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

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 

热点排行