有表tableA,其中有一个字段mobile
要求查询出记录中同一mobile出现次数少于6次的数据,并且还要知道这个mobile有多少条记录。

解决方案 »

  1.   

    select mobile,count(1) from tb group by mobile having count(1)<6我是来看楼主头像的。
      

  2.   

    select mobile,count(*) from tableA group by mobile
    having count(*)>6
      

  3.   


    select mobile,次数=count(*) from tableA group by mobile
    having count(*)<6
      

  4.   

    FYI.
    ;with MobileAgregation
    as
    (
      select 
        Mobile
      , COUNT(1) times
      from dbo.TableA
      group by Mobile
    )
    select Agr.times, TA.*
    from MobileAgregation agr
    join dbo.TableA TA
      on agr.Mobile = TA.Mobile
     where agr.times < 6;
      

  5.   

    select * from tb ,(select mobile,次数=count(*) from tableA group by mobile
    having count(*)<6) a where .....
      

  6.   

    select mobile,count(1) from tb  group by mobile
    having count(1)<6
      

  7.   

    select
      * 
    from
      tb 
    where
      mobile 
    in
      (select mobile from tb group by mobile having count(1)<6)
      

  8.   

    初接触SQL正在学习中学习再学习!