写了如下语句:
select xl as xl,sum(yye+yp) as yyze from yy_ryye 
 where rq>='2008-01-01' and rq<='2008-09-25' and xl<>'31' and xl<>'41' group by xl
请教如何在其中取出最大值呢?显示出xl及yyze两项数据?

解决方案 »

  1.   

    select top 1 xl as xl,sum(yye+yp) as yyze from yy_ryye 
    where rq>='2008-01-01' and rq <='2008-09-25' and xl <>'31' and xl <>'41' 
    group by xl 
    order by 2
      

  2.   

    select xl as xl,max(yye+yp) as yyze from yy_ryye 
    where rq>='2008-01-01' and rq <='2008-09-25' and xl <>'31' and xl <>'41' group by xl 
      

  3.   

    select top 1 xl as xl,sum(yye+yp) as yyze from yy_ryye 
    where rq>='2008-01-01' and rq <='2008-09-25' and xl <>'31' and xl <>'41' 
    group by xl 
    order by 2 desc
      

  4.   

    order by 2 是什么意思?
      

  5.   

    select top 1 xl,yyze  from (select xl as xl,sum(yye+yp) as yyze from yy_ryye 
    where rq>='2008-01-01' and rq <='2008-09-25' and xl <>'31' and xl <>'41' group by xl ) as yy_ryye_tmp
    order by yyze desc