我的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)

解决方案 »

  1.   

    insert into t
    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)
      

  2.   

    我这里写了两列,姓名和活动,你可以在后面加第三列,第四列,如果很多也可以用函数+临时表来循环写等本人sql水平有限,就算帮你顶吧~~~~``
      

  3.   

    不好意思我在sql server里测试的~~~讲思路吧~
    先将字段一分组,然后取每组的最大值,
    字段二也一样~~