select UserID from 表 group by UserID having sum(Counts)>200

解决方案 »

  1.   


    select UserID from table
    group by UserID having SUM(Counts)>200
      

  2.   


    create table #t(ID int,UserID varchar(20),Counts int,InYear int)
    insert into #t(ID,UserID,Counts,InYear)
    select 1,'001',100,2005 union all
    select 2,'002',140,2005 union all
    select 3,'003',120,2005 union all
    select 4,'001',130,2006 union all
    select 5,'002',150,2006 union all
    select 6,'003',150,2006select UserID 
    from #t 
    group by UserID 
    having sum(Counts)>200drop table #t/*UserID
    001
    002
    003*/