这是我现在在我的查询:MySQL的:选择MAX值和分组
+--------------------+-----------+------------+
| status | entity_id | seconds |
+--------------------+-----------+------------+
| Submitted | 494 | 1352102400 |
| Accepted | 494 | 1352275200 |
| In press/e-publish | 494 | 1352966400 |
| Rejected | 520 | 1355817600 |
| Accepted | 570 | 1352102400 |
+--------------------+-----------+------------+
我希望它看起来像:
+--------------------+-----------+------------+
| status | entity_id | seconds |
+--------------------+-----------+------------+
| In press/e-publish | 494 | 1352966400 |
| Rejected | 520 | 1355817600 |
| Accepted | 570 | 1352102400 |
+--------------------+-----------+------------+
在准SQL:
SELECT status, entity_id, MAX(seconds)
FROM foo
GROUP BY entity_id, seconds
上面的准SQL看起来是正确的,但“状态”列值不对应正确的行。我得到类似的东西在下面:
+--------------------+-----------+------------+
| status | entity_id | seconds |
+--------------------+-----------+------------+
| Submitted | 494 | 1352966400 |
| Rejected | 520 | 1355817600 |
| Accepted | 570 | 1352102400 |
+--------------------+-----------+------------+
直到现在还没有听说过SQL小提琴。幸运的是,下面的海报为我们创建了SQL Fiddle页面(http://sqlfiddle.com/#!2/e6ab2/12),并且我能够测试您的查询,并且它的工作原理除了“==”,课程。 :) – user785179
Doh!这是一个非常愚蠢的错误,使... ...(脸红)特别是因为我有正确的三行下来。 – Amadan