select *,maxsign_step=(select max(sign_step) from @table where type=t.type) from @table t这样?
select * from @table a where exists( select 1 from (select type,max(sign_step) sign_step from @table group by type)T where a.Type=T.Type and a.sign_step = T.sign_step)
select signid,[type],max(rank) from ( select *,row_Number() over(partition by [type] order by signid desc) rank from @table )T group by signid,[type]
或者:select * from @table t where not exists(select 1 from @table where type=t.type and sign_step>t.sign_step)
select * from @table t where not exists(select 1 from @table type=t.type and sign_step>t.sign_step)
select * from @table t where sign_step in(select top 1 sign_step from @table where type=t.type order by sign_step desc)
我用嵌套查询实现了。 就是 select a.signid from @table a,(select type,max(sign_step) as sign_step from @table group by type) b where a.type=b.type and a.sign_step = b.sign_step 谢谢各位!结贴给分了
select * from @table a where exists( select 1 from
(select type,max(sign_step) sign_step from @table group by type)T where a.Type=T.Type and a.sign_step = T.sign_step)
(
select *,row_Number() over(partition by [type] order by signid desc) rank from @table
)T group by signid,[type]
*
from
@table t
where
sign_step in(select top 1 sign_step from @table where type=t.type order by sign_step desc)
就是
select a.signid
from @table a,(select type,max(sign_step) as sign_step from @table group by type) b
where a.type=b.type
and a.sign_step = b.sign_step
谢谢各位!结贴给分了