表H_ENTRY_WORKFLOW 字段 ENTRY_ID,STEP_ID
记录如下
select ENTRY_ID,STEP_ID from H_ENTRY_WORKFLOW order by ENTRY_ID,STEP_ID asc
ENTRY_ID STEP_ID
-------------------------------------
090120061016209152 00000000
090120061016209152 00000000
090120061016209152 10000000
090120061016209152 10000000
090120061016209152 20000000
090120061016209152 30000000
090120061016209152 30000000
090120061016209152 40000000
090120061016209152 40000000
090120061016209152 70000000
090120061016209152 80000000(*)
090120061016209155 00000000
090120061016209155 10000000
090120061016209155 20000000
090120061016209155 30000000
090120061016209155 40000000(*)
我要实现的是如何得到
090120061016209152 80000000(*)
090120061016209155 40000000(*)
这俩条数据!!!
------解决方案--------------------
select ENTRY_ID, max(STEP_ID)
from H_ENTRY_WORKFLOW
group by ENTRY_ID
order by ENTRY_ID,STEP_ID asc
------解决方案--------------------
select * from H_ENTRY_WORKFLOW t
where not exists(select 1 from H_ENTRY_WORKFLOW where ENTRY_ID = t.ENTRY_ID and STEP_ID > t.STEP_ID)
------解决方案--------------------
select * from H_ENTRY_WORKFLOW t
where t.STEP_ID(select max(t.STEP_ID) from H_ENTRY_WORKFLOW where ENTRY_ID = t.ENTRY_ID)
------解决方案--------------------
select ENTRY_ID,max(STEP_ID)
from H_ENTRY_WORKFLOW
group by ENTRY_ID
order by ENTRY_ID,STEP_ID asc