当前位置: 代码迷 >> Sql Server >> 请教怎么取2列中,a列最大值所对应的另一列数值
  详细解决方案

请教怎么取2列中,a列最大值所对应的另一列数值

热度:78   发布时间:2016-04-24 20:57:11.0
请问如何取2列中,a列最大值所对应的另一列数值?
表结构如下
A   B
aa   2013-12
bb   2013-01

我现在想得到的值是aa 


即先判断出B列时间最大的那一个,然后只取对应B列的A值?



------解决方案--------------------
先用子查询取最大值,再用 in 作为条件
select * from t where b in(select max(b) from t)

------解决方案--------------------
select A from tb with(nolock) 
where B=(
  select max(B) from tb with(nolock)
)
  相关解决方案