我有这样两个字段
nd            number
2002            500
2001            800
2003            400我想找到max(nd)所对应的number数字
这条SQL语句怎么写呢

解决方案 »

  1.   

    select number from tablename
    where nd = (select max(nd) from tablename)
      

  2.   


    select top 1 number from tablename order by nd desc
      

  3.   

    nd  字段是否有重复的select * from tablename where nd=max(nd)
      

  4.   

    忘了说了,我前面还有一个字段是学好
    学号     nd            number
    01      2002            500
    01      2001            800
    01      2003            400
    统计的是一个学好的 max(nd)的 number值?
    不好意思
      

  5.   

    select 学号,number from tablename
    where nd = (select max(nd) from tablename)就是啦,还有什么吗?
      

  6.   

    那就要这样select a.number from tablename a
    inner join (select 学号,max(nd) as nd from tablename group by 学号) b on a.学号=b.学号 and a.nd = b.nd
      

  7.   

    select distinct 学号,number from table1 a inner join
    (select 学号,max(nd) as maxValue from table1 group by 学号) as b
    on a.学号=b.学号 and a.nd=b.nd