我的sql是凑出来的楼主参考参考~~create table t(n nvarchar(20),c nvarchar(20))insert into t
select '小明','课外活动' union all
select '小王','体育' union all
select '小明','课外活动' union all
select '小赵','课外活动' union all
select '小王','体育' union all
select '小王','课外活动'select n=(select top 1 n from (select n,count(n) as nCount from t group by n) a order by nCount desc)
,c=(select top 1 c from (select c,count(c) as cCount from t group by c) b order by cCount desc)
select '小明','课外活动' union all
select '小王','体育' union all
select '小明','课外活动' union all
select '小赵','课外活动' union all
select '小王','体育' union all
select '小王','课外活动'select n=(select top 1 n from (select n,count(n) as nCount from t group by n) a order by nCount desc)
,c=(select top 1 c from (select c,count(c) as cCount from t group by c) b order by cCount desc)
select '小明','课外活动' union all
select '小王','体育' union all
select '小明','课外活动' union all
select '小赵','课外活动' union all
select '小王','体育' union all
select '小王','课外活动'这个只是测试数据,你可以用自己的数据
代码是这个sql
select n=(select top 1 n from (select n,count(n) as nCount from t group by n) a order by nCount desc)
,c=(select top 1 c from (select c,count(c) as cCount from t group by c) b order by cCount desc)
先将字段一分组,然后取每组的最大值,
字段二也一样~~