日期:2014-05-17  浏览次数:20367 次

请问如何取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)
)