Reputation: 1057
This is my table offs
:
date ---------- oid ------ head ----- cnt
2012-1-9 -----13 -------- 10 -----------1
2012-1-11 --- 13 -------- 6 ----------- 2
2012-1-22 --- 13 -------- 10 -----------3
2012-1-22 --- 11 -------- 10 -----------4
I need a select function with a result the max(date)
from oid and distinct head, like that:
2012-1-11 --- 13 -------- 6 ----------- 2
2012-1-22 --- 13 -------- 10 -----------3
2012-1-22 --- 11 -------- 10 -----------4
Upvotes: 0
Views: 5017
Reputation: 18629
How about this query:
SELECT a.*, b.cnt from(
SELECT MAX(Date) AS Date, oid, head
from offs group by oid, head
)a inner join offs b on a.Date=b.Date and a.oid=b.oid and a.head=b.head
Upvotes: 1