SELECT company_code,max(update_date),input_money
 FROM test1  group by company_code;

解决方案 »

  1.   

    楼上的,问题没有那么简单,用你的语句,查询出来的input_money数是错的。
      

  2.   

    SELECT company_code,max(update_date),input_money  FROM test1  group by company_code,input_money;
    运行结果:
     company_code |    max     | input_money
    --------------+------------+-------------
     01           | 2003/03    |       10000
     01           | 2003/07    |       20000
     01           | 2003/05    |       30000
     01           | 2003/06    |       40000
     02           | 2003/04    |       20000
     02           | 2003/05    |       30000
    (6 rows)
    结果不对。
      

  3.   

    select a.company_code,a.input_money, b.update_date from test1 a ,(select company_code,max(update_date) as update_date  from test1 group by company_code) b  where b.company_code = a.company_code and a.update_date=b.update_date
      

  4.   

    楼上的是PostgreSql的语法吗?
    只懂MySQL,看不懂:P
      

  5.   

    是MySQL的语法,他用的子查询 ^_^
      

  6.   

    谢谢yzssg(秋枫) 的sql,运行速度真的快了很多。
    谢谢lierq(李子) ,Arbow(◎_◎) ,swotcoder(苦 丁) ,neumqp(风之子) 对这个帖子的关注和参与。
    如果各位还有更好的方法,或者别的什么方法,希望大家贴出来。
    谢谢各位。
      

  7.   

    select company_code,max(update_date),input_money
    from td_temp
    group by company_code;
    我试过了,行!
      

  8.   

    上面写的不对!重写:
    先建立一临时表:
    create table td_temp1
    select company_code,max(update_date) update_date
    from td_temp
    group by company_code;
    再联立两个表:
    select a.* from td_temp a,td_temp1 b
    where a.company_code=b.company_code
    and a.update_date=b.update_date
    肯定行!
      

  9.   

    :P没有用过MySQL的子查询既然可以用子查询,那么应该用left join也行的吧,那位高手给出一个语句?
      

  10.   

    MySql不支持子查询,但支持left join
    如果当前表(td_temp)与自己(td_temp)联立,数据量大时,sql语句的效率很低,数据库容易死掉。
      

  11.   

    "MySql不支持子查询,但支持left join"4.0版本以上支持子查询