select max(_n) from 
(select hm as _hm,jz as _jz,count(hm) as _n 
from ab.dbo.xd4 
where jz in (select jz from ab.dbo.xdjz)
group by hm,jz order by _hm,_n desc ) as tablename

解决方案 »

  1.   

    改:
    select _hm,_jz,max(_n) from 
    (select hm as _hm,jz as _jz,count(hm) as _n 
    from ab.dbo.xd4 
    where jz in (select jz from ab.dbo.xdjz)
    group by hm,jz order by _hm,_n desc ) as tablename
    group by _hm,_jz
      

  2.   

    select _hm,max(_n) from 
    (select hm as _hm,jz as _jz,count(hm) as _n 
    from ab.dbo.xd4 
    where jz in (select jz from ab.dbo.xdjz)
    group by hm,jz order by _hm,_n desc ) as tablename
    group by _hm
      

  3.   

    如何在 分组 查询 中 只 选出 纪录 最多的组?
    select hm as _hm,jz as _jz,count(hm) as _n 
    from xd4 
    where jz in (select jz from xdjz)
    group by hm,jz order by _hm,_n desc
    只想选出 同一个hm 中 _n 最大的纪录
    或者在
    hm jz n 三个字段的表中
    号码相同的纪录有很多,对应不同的 jz ,n 
    现在只想挑出 同一个号码 n 最大的纪录
    的所有号码,对应的jz,n的集合
      

  4.   

    如何在 分组 查询 中 只 选出 纪录 最多的组?select * from ab.dbo.xd4 where hm in (select top 1 hm from ab.dbo.xd4 group by hm order by count(*) desc)
      

  5.   

    select  top 1 hm as _hm,jz as _jz,count(hm) as _n 
    from xd4  where jz in (select jz from xdjz)
    group by hm,jz 
    order by count(hm) desc
      

  6.   

    select T1.*,T2.jz 
    (select hm ,count(*) as cnt  from ab.dbo.xd4  
    where hm in 
    (select top 1 hm from ab.dbo.xd4 group by hm order by count(*) desc)
    group by hm
    ) T1
    inner join xdjz T2 ON T1.hm=T2.hm