SQL内部联接 - 获取最大值

时间:2013-10-20 11:45:08

标签: sql oracle oracle11g

与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

2 个答案:

答案 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