日期:2014-05-19  浏览次数:20520 次

如何取A列中最大值所对应的B列值?
A                       B
530630             CC
530635             EE      
530639             DD

--需要显示A列中最大值(530639)所对应的B列的名称(EE),只需要得出以下形式结果:
B
DD

--请教高手是否可写自定义函数或其他什么之类的,谢谢...

------解决方案--------------------
select B from 表 a where not exists(select 1 from 表 where A > a.A)
------解决方案--------------------
Select TOP 1 B From 表 Order By A Desc
------解决方案--------------------
学习
------解决方案--------------------
declare @t table(A int ,B nvarchar(200))
insert into @t select 530630, 'CC '
insert into @t select 530635, 'EE '
insert into @t select 530639, 'DD '

select B
from @t
where A in(select max(A) from @t)
------解决方案--------------------
select B from table_name where A=(select max(A) from table_name)
------解决方案--------------------
等待牛人来答.