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 |
+---------------------+还望高手帮忙给个提示
| 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 |
+---------------------+还望高手帮忙给个提示
from ExampleTable
where id=333
and `datetime` = (select max(`datetime`) from ExampleTable where id=333 );
from ExampleTable a
where id=333
and not exists (select id from ExampleTable where id=a.id and `datetime`>a.`datetime`);
datetime 是保留字,不建议做为列名。
(select max(`datetime`) as ma from ExampleTable where id=333) b on a.`datetime`=b.ma
Subquery returns more than 1 row
select * from file_table where fvid=29823
and modifytime = (select modifytime from file_table where fvid=29823 );