select max(id) from (select top 50  id from table  )

解决方案 »

  1.   

    用"SELECT DISTINCT TOP 50 max(Id) FROM 表名"  就OK了!
      

  2.   

    select max(medicine_id) from medicine where exists (select top 50 * from medicine order by medicine_id desc)
      

  3.   

    "select  top "+SetMixId+" max(id)  from admin_user order by id "  
    这个有问题吗??  SetMixId 确实是有值的。
      

  4.   

    select max(ID) from (select top 50 ID from 表名)
      

  5.   

    select max(id)  from (select  top 50 id from admin_user order by id )这样不行啊,,,晕。。提示语法有错误。
      

  6.   

    楼主看这个好不好使,至少我的是好使的。Select top 50 max(id) as Max_ID from yourTable上面的ID应该是你所说的ID字段,yourTable是你要查询的那张表。试试吧!
      

  7.   

    这样子吧。select top 50 ID from 表名 order by ID desc
    这样子取出来 第一条记录就是最大的了。因为是降序排列。你试试,不行再帮你想其它的。
      

  8.   

    晕死了,大家帮我看看把,谢谢了。private int GetMix(int SetMixId)
    {
    DataOperate mydo=new DataOperate();
    mydo.SqlString="select max(id) as mixid1 from admin_user where exists( select  top "+SetMixId+" id from admin_user order by id )";
    SqlDataReader my_reader=mydo.select_sqldatareader();
    int mix_id=0;

    mix_id=int.Parse(my_reader["mixid1"].ToString());
    my_reader.Close();
    return mix_id;
    }
    提示 这个 有问题 mix_id=int.Parse(my_reader["mixid1"].ToString());
      

  9.   

    忘了给你排序了,这句完整:Select max(id) as Max_ID from yourTable where id in(select top 50 id from yourTable order by id)再试试!
      

  10.   

    select max(id)  from (select  top 50 id from admin_user order by id )这样不行啊,,,晕。。提示语法有错误。
    -------------------------------------------------------------------------
    这样就是对的呀
      

  11.   

    老兄你跟踪一下my_reader["mixid1"].ToString()有值吗?
      

  12.   

    -->shoutor(土人制造)select max(id) as mixid1 from (select  top 50 id from admin_user order by id ) DERIVEDTBL这样肯定对的。
      

  13.   

    搞什么,CSDN 老是超时,刚才写了一大版,现在什么都没有了。。我再看看,是不是其他地方有问题
      

  14.   

    to: LorenShore(代码人生) Select max(id) as Max_ID from yourTable where id in(select top 50 id from yourTable order by id)
    这个是对的
    确实是我的 my_reader["mixid1"] 没有值,但是我现在用什么判断my_reader["mixid1"]是否一直比较好??
      

  15.   

    再给你一段:Select ISNULL(max(id),-1) as Max_ID from yourTable where id in(select top 50 id from yourTable order by id)肯定能返回一条值,没有则返回-1试试
    我下班了