与recordKey相关的2个表:
TransId recordKey
44 111
56 234
HistoryId recordKey ProcessTime
1 111 0
2 111 200
3 111 4000
4 234 10
如何加入此表,以便在分组时,只获得最大处理时间(4000)?
更新:结果如下:
TransId ProcessTime
44 4000
55 10
答案 0 :(得分:5)
SELECT transId, MAX(processTime)
FROM transaction
JOIN history ON history.recordKey = transaction.recordKey
GROUP BY transId
答案 1 :(得分:0)
也许是这样的?
select transid,transaction.recordkey,max(history.processtime)
from transaction, history
where transaction.recordkey=history.recordkey
group by transid,transaction.recordkey