这个简单的查询有什么不对?

时间:2015-01-16 02:03:33

标签: sql-server

select ReplenishDate,Amount
from vw_replenishmentData
where (select max(ReplenishDate) from vw_replenishmentData)

2 个答案:

答案 0 :(得分:1)

您的where语句无效,请尝试以下操作:

select ReplenishDate,Amount 
from 
vw_replenishmentData 
where ReplenishDate= (select max(ReplenishDate) maxDate from vw_replenishmentData)

答案 1 :(得分:1)

问题是您需要在哪里使用列名来过滤结果,例如.. where columnname = (select max(...

而不是使用subquery使用Top 1 with Ties

select Top 1 with ties ReplenishDate,Amount
from vw_replenishmentData
order by ReplenishDate desc