本帖最后由 zjdns 于 2012-05-04 20:40:48 编辑

解决方案 »

  1.   

    参考下贴中的多种方法http://blog.csdn.net/acmain_chm/article/details/4126306
    [征集]分组取最大N条记录方法征集,及散分....
      

  2.   

    参数 值 获取时间 批号select *
    from tb A
    where not exists (select 1 from tb B where A.参数=B.参数 and A.值=B.值 and A.获取时间<B.获取时间)
      

  3.   

    参数名称 我想挑选几个出来, 然后查找几个最新的时间和值,
    每个名称只显示一次.
    如果用很笨的方法是
    先给予几个需要的参数:$codelist="281,282,285,288,358";
    $codearr=explode(',',$codelist);
    foeach ($codearr as $v){ $id= " select id form teble where code= '$v'  order by uptime desc limit 0.1"; 
    执行$sql后得到这个参数的行ID,  $idlist .=$id.',';
    }//然后再执行  $list= " select * form teble where id in ($idlist)  order by uptime desc "; 
    //执行$sql后得到这个参数的行ID, 
    //这样就可以得到指定code(参数)281,282,285,288,358 这5个代码的最新值和最后时间
    这个方法是先用foreach 得出每个code的最新id
    然后在 in idlist这个方法是我很傻的想法, 我知道能实现, 我想问问有没有直接一句 sql语句能得出这个结果的
    同时也考虑效率比我这个更高还是效率会低一些, 建议采用那种方法?请赐教
      

  4.   

    这样应该可以吧:
    select * form teble where id in (select distinct id from teble)  order by uptime desc