数据:
排列号    名字    数量   日期
001        a      4      2010-10
002        b      4      2010-10
003        a      2      2010-10
004        b      3      2010-10
005        c      10     2010-10
005        c      0      2010-10
006        d      5      2010-10
006        d      0      2010-10结果:
排列号    名字    数量   日期
003       a        2     2010-10
004       b        3     2010-10
 
非常着急,在线等待!!

解决方案 »

  1.   

    select max(排列号) 排列号 , 名字 , count(1)  数量 , 日期 from tb group by 名字, 日期
      

  2.   

    select *
    from tb t
    where
    not exists(select 1 from tb where 名字=t.名字 and 数量=0)
    and
    not exists(select 1 from tb where 名字=t.名字 and 数量<t.数量)
      

  3.   


    哈哈, 来猜一个结果。。
    -- =============================================
    -- Author:      T.O.P
    -- Create date: 20091128
    -- Version:     SQL SERVER 2000
    -- =============================================
    declare @tb1 table([排列号] varchar(3),[名字] varchar(1),[数量] int,[日期] varchar(7))
    insert @tb1
    select '001','a',4,'2010-10' union all
    select '002','b',4,'2010-10' union all
    select '003','a',2,'2010-10' union all
    select '004','b',3,'2010-10' union all
    select '005','c',10,'2010-10' union all
    select '005','c',0,'2010-10' union all
    select '006','d',5,'2010-10' union all
    select '006','d',0,'2010-10'select p.*
    from (
    select * 
    from @tb1 a
    where a.名字 not in (select 名字 from @tb1 where 数量=0)
         ) p
    where not exists(select 1 from @tb1 where p.名字=名字 and p.数量>数量)
    --测试结果:
    /*排列号  名字   数量          日期      
    ---- ---- ----------- ------- 
    003  a    2           2010-10
    004  b    3           2010-10(所影响的行数为 2 行)*/
      

  4.   

    select * from @tb1 as t where t.排列号 in ( select MAX([排列号]) from @tb1 as t group by 名字)