ExampleTable的datetime时间列, 如果datetime不一样的,找到最大的,要是有3个一样最大都列出来。 如果datetime一样就都列出来。我用了MAX()函数,它只能返回一行这样的结果。SELECT MAX(datetime) FROM ExampleTable WHERE id=333;+---------------------+
| MAX(datetime)     |
+---------------------+
| 2001-08-28 07:34:00 |
+---------------------+
1 row in set (0.00 sec)而我想要的结果是:
+---------------------+
| datetime|
+---------------------+
| 2001-08-28 07:34:00 |
| 2001-08-28 07:34:00 |
+---------------------+还望高手帮忙给个提示

解决方案 »

  1.   

    select * 
    from ExampleTable
    where id=333 
    and `datetime` = (select max(`datetime`) from ExampleTable where id=333 );
    
      

  2.   

    或者select * 
    from ExampleTable a
    where id=333 
    and not exists (select id from ExampleTable where id=a.id and `datetime`>a.`datetime`);
    datetime 是保留字,不建议做为列名。
      

  3.   

    select a.* from ExampleTable a inner join
    (select max(`datetime`) as ma from ExampleTable where id=333) b on a.`datetime`=b.ma
      

  4.   

    语句返回的结果:
    Subquery returns more than 1 row
      

  5.   

    第二个好用,谢谢~ 给分。 原来表的列名不叫datetime 而是modifytime。
      

  6.   


    select * from file_table where fvid=29823
    and modifytime = (select modifytime from file_table where fvid=29823 );