读书人

怎么取A列中最大值所对应的B列值

发布时间: 2012-02-01 16:58:19 作者: rapoo

如何取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)
[解决办法]
等待牛人来答.

读书人网 >SQL Server

热点推荐