-2

2个与recordKey相关的表:

交易表

TransId   recordKey
44          111
56          234 

历史表

HistoryId   recordKey   ProcessTime
1              111              0
2              111              200
3              111              4000
4              234              10


如何加入此表,以便在分组时仅获得最大处理时间(4000)?

更新:结果将如下所示:

TransId 处理时间
44 4000
55 10

4

2 回答 2

5
SELECT   transId, MAX(processTime)
FROM     transaction
JOIN     history ON history.recordKey = transaction.recordKey
GROUP BY transId
于 2013-10-20T11:49:13.587 回答
0

也许是这样的?

select transid,transaction.recordkey,max(history.processtime) 
from transaction, history 
where transaction.recordkey=history.recordkey 
group by transid,transaction.recordkey
于 2013-10-20T11:49:54.047 回答