我有这个表:选择使用MAX和组的所有相应的字段BY
,我想提出,将返回每个deal_id
最高timestamp
,和该行的请求相应的status_id
。
所以在这个例子中,我将返回2行:
1226, 3, 2009-08-18 12:10:25
1227, 2, 2009-08-17 14:31:25
我试图与此查询
SELECT deal_id, status_id, max(timestamp) FROM deal_status GROUP BY deal_id
做到这一点,但它会返回错误status_id
:
1226, 1, 2009-08-18 12:10:25
1227, 1, 2009-08-17 14:31:25
的可能重复[获取具有最大值列的行](http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column) – outis 2011-12-23 02:32:14