I have this table :
And I would like to make a request that would return for each deal_id
the row with the highest timestamp
, and the corresponding status_id
.
So for this example, I would have returned 2 rows :
1226, 3, 2009-08-18 12:10:25
1227, 2, 2009-08-17 14:31:25
I tried to do it with this query
SELECT deal_id, status_id, max(timestamp) FROM deal_status GROUP BY deal_id
but it would return the wrong status_id
:
1226, 1, 2009-08-18 12:10:25
1227, 1, 2009-08-17 14:31:25
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…