select count(phone) from 表名 group by phone having count(phone)>=某值

解决方案 »

  1.   

    select id, count(phone) as phone_count
    from table
    order by count(phone) desc
      

  2.   

    declare @row int
    set @row = 3
    select id, phone from yourtable where phone in 
    (select phone from yourtable group by phone having count(phone) >= @row)
      

  3.   

    declare @tem int
    set @tem=3
    select id,count(phone) 
    from yourtalbe
    group by id 
    having count(phone)>=@tem
    order by count(phone) desc
      

  4.   

    如果想取排名,可以这样:select IDENTITY(int, 1,1) AS seq, X.id, X.phone, X.phone_count
    from (select id, phone, count(phone) as phone_count
            from table_name
           group by id, phone
           order by count(phone) desc) X
    这样排名就出来了。
    比如想取排名第二的:
    select Y.id, Y.phone, Y.phone_count
    from (select IDENTITY(int, 1,1) AS seq, X.id, X.phone, X.phone_count
            from (select id, phone, count(phone) as phone_count
                    from table_name
                   group by id, phone
                   order by count(phone) desc) X ) Y
    where Y.seq = 2
      

  5.   

    select phone from table group by phone having count(phone)>insert into #
    select IDENTITY(int, 1,1) AS seq,phone
    from (select phone from table group by phone  order by count(phone) desc) a
      

  6.   

    只查号码:
    select phone from yourtable group by phone having count(phone) >= @row
      

  7.   

    select phone,count(phone)
    from table
    group by phone
    having count(phone)>=yournumber
      

  8.   

    select identity(int,1,1) as 排名, count(phone) as 次数 , phone as 号码
    into #temp
    from 表名 group by phone order by count(phone) desc那么查询最多的:
    select 号码 from #temp where 排名=1    
    第二多的:
    select 号码 from #temp where 排名=2
      

  9.   

    select id from yourtable group by id
      

  10.   

    select id,count(id) from yourtable group by id order by id desc
      

  11.   

    select id from yourtable group by id
      

  12.   

    select count(phone) as phone_count from yourtable group by phone
    order by count(phone) desc
      

  13.   

    select phone,count(phone)
    from table
    group by phone
    having count(phone)>=yournumber
      

  14.   

    select [name],re from test group by [name],re having count([name]) >= 2
    其中test為表名,name,re為字段名