数据如下:
工单号         完成时间毫秒值
000001         1355662903
000001         1355662904
000001         1355662905
000002         1355662907
000002         1355662908我想取到000001         1355662905和000002         1355662908,也就是相同工单号里,完成时间最大的值。sql如下:select c1, c2 from table1
这个sql要集成到另一个大sql里,而且要根据条件拼接。能不能用个函数或者什么最简单的方法取到我要的值,谢谢!

解决方案 »

  1.   


    select c1, max(c2) c2 
    from table1
    group by c1
      

  2.   


    这个sql里还有10几个其他字段,里面包含好几个函数,group by不管用吧
      

  3.   


    select c1,c2,c3...
    from
    (
        select c1,c2,c3..,
               row_number() over(partition by c1 order by c2 desc) rn
        from table1
    )
    where rn = 1
      

  4.   

    ①.select c1, max(c2) from table1 group by c1;
    ②.select * from table1 where (c1.c2) in (select c1, max(c2) from table1 group by c1);
      

  5.   

    select c1, max(c2) from table1 group by c1;
    意思按c1分组,只要是c1列相同就只显一条记录,可以用聚合操作显示其他列,如max最大值,min最小值,count这组数有多少条