select top 1 with ties * from a order by len(mc)desc
select * from (select dm,mc,len(mc) as len_mc a ) as A where A.len_mc=(select max(len(mc)) from a)
--生成测试数据 if object_id('tb') is not null drop table tb go create tb(dm nvarchar(10), mc nvarchar(50)) insert tb select '001', 'a' union all select '002', 'ab' union all select '003', 'abcdef' union all select '004', 'abc' union all select '005', 'abcde' --你要的语句 select top 1 * from tb order by len(mc) desc
from a
order by len(mc) desc
from a
order by len(mc)desc
select * from
(select dm,mc,len(mc) as len_mc a ) as A
where A.len_mc=(select max(len(mc)) from a)
if object_id('tb') is not null
drop table tb
go
create tb(dm nvarchar(10), mc nvarchar(50))
insert tb
select '001', 'a' union all
select '002', 'ab' union all
select '003', 'abcdef' union all
select '004', 'abc' union all
select '005', 'abcde'
--你要的语句
select top 1 * from tb order by len(mc) desc