[英]Error on getting corresponding dateTime of max value
Table 'test' 表“测试”
+------+--------------------+
|value | dateTime |
+------+--------------------+
|19 |2011-12-22 11:09:42 |
+------+--------------------+
|16 |2011-12-22 05:09:00 |
+------+--------------------+
|2 |2011-12-22 07:09:42 |
+------+--------------------+
|30 |2011-12-22 10:09:15 |
+------+--------------------+
|45 |2011-12-22 03:09:42 |
+------+--------------------+
I would like to get the Max value and its corresponding dateTime. 我想获取Max值及其对应的dateTime。 In this case, the final result should be: max value:45 and dateTime:2011-12-22 03:09:42 .
在这种情况下,最终结果应该是: 最大值:45和dateTime:2011-12-22 03:09:42 。 I used
我用了
SELECT MAX( `value` ) , `dateTime`
FROM `test`
After running the above sql statement, the max 'value' is correct (ie 45), but the 'dateTime 'is not correct (ie2011-12-22 11:09:19) 运行上述sql语句后,最大值“ value”正确(即45),但“ dateTime”不正确(即2011-12-22 11:09:19)
Is there anyone can help me? 有没有人可以帮助我? Many thanks!
非常感谢!
try this: 尝试这个:
SELECT TOP 1 `value`, `dateTime`
FROM `test`
ORDER BY `value` DESC
-- general
select *
from test
where value= (select max(value) from test)
or 要么
--tsql
select top 1 *
from test
order by value desc
or 要么
--mysql
select *
from test
order by value desc
limit 1;
There is a bug in MySQL in version 5.5. MySQL 5.5版中有一个错误。 Try upgrading MySQL.
尝试升级MySQL。 Your code is not the problem.
您的代码不是问题。
http://bugs.mysql.com/bug.php?id=54784 http://bugs.mysql.com/bug.php?id=54784
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.