select a.*,(case when a.b=b.b then 'Y' else 'N' end) as IfMax 
from table a,
(select a,max(b) as b from table group by a) b 
where a.a=b.a

解决方案 »

  1.   

    select a,b ,'N'  from table where a>b
    union
    select a,b ,'Y'  from table where a<=b
      

  2.   

    select *,case when b = (select max(b) from Tab where a = t1.a) then 'Y'
              else 'N' end
    from Tab T1
      

  3.   

    select *
           ,case when b = (select max(b) from ab where a = t1.a) when 'Y' else 'N' end AS ifmax
    from ab T1
      

  4.   

    to  j9988(j9988) : 呵呵, 谢谢, 搞定了to zqllyh:
    如果记录如下,你的方法是不行的, :)
    a b
    -----------------
    10 1
    10 2
    10 3
    10 4
    2 1
    2 20
      

  5.   

    select *
           ,case when b = (select max(b) from Tab where a = t1.a) when 'Y' else 'N' end AS ifmax
    from Tab T1这个难道不更好马?!