34,587
社区成员
发帖
与我相关
我的任务
分享
上面没看清要分组,楼上两位的写法简单,只是提供一下别的写法
update #temp
set sm='最长'
from
(select MAX(dah) dah from #temp a where len(dah)in(select max(len(dah)) from #temp group by XM)
group by xm) a
where #temp.dah =a.dah
再一种
update ryb
set sm='最长'
from
(select top 1 * from ryb a where len(dah)=(select max(len(dah)) from ryb )
order by dah desc)a
where ryb.dah =a.dah
WITH a AS (
SELECT ROW_NUMBER()OVER(PARTITION BY xm ORDER BY CAST(dah AS INT)desc) id,* FROM ryb
)
UPDATE ryh SET sm='最长' WHERE dah IN (SELECT dah FROM a WHERE id=1)
update t set sm='最长'
from
( select * ,
row_number()over(partition by xm order by len(dah) desc,dah desc)as n from ryb ) t
where n=1