当前位置: 代码迷 >> Sql Server >> 一条SQL语句!解决思路
  详细解决方案

一条SQL语句!解决思路

热度:7   发布时间:2016-04-27 17:34:04.0
一条SQL语句!
表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
  相关解决方案