我有 2 张桌子:
桌子workflow
Request_Id, Step ID
123, 4
123, 7
198, 5
桌子Steps
Step_Id, Step_num
4, 30
7, 12
5, 172
我正在尝试返回表 Workflow 中的所有记录,其中 Steps.step_num 是该记录的最大值。我的结果应该是这样的:
Request_Id, Step_Id, Step_Num
123, 4, 30
198, 5, 172
我试过这个,但我没有得到正确的 Step_ID:
select request_id, step_id,max(step_num) from
(
select ww.request_id as request_id, ww.step_id as step_id, st.step_num as step_num
from workflow ww
left join steps st on ww.step_id=st.step_id) as s
group by request_id
请帮忙,我卡住了:)