SELECT MAX(zskid) FROM (select top 131000 * from taoluTable) AS T上面sql语句为什么查出来的max(zskid)是taoluTable的最大值,而不是top 131000里面的最大值呢?

解决方案 »

  1.   

    没有order by的top……啧啧……
      

  2.   


    declare @t table (col int)
    insert into @t
    select 1 union all
    select 3 union all
    select 5 union all
    select 7 union all
    select 9select max(col) from (select top 3 * from @t) as t
    /*
    5
    */
    用的top的时候,里面最好写上order by
      

  3.   

    还真是order by的问题,问什么要加上order by才行呢?
    SELECT MAX(zskid) FROM (select top 131000 * from taoluTable order by zskid) AS temp这样就可以
    不加上order by不也是从一个集合里面读取最大值吗?