获取最新的更新记录

时间:2012-11-05 05:32:36

标签: sql sql-server-2008

我在SQL Server 2008中有一个“观察”表。此表有一组locationId列,用于显示一组地理位置,一些列用于观察详细信息,另一列用于最新更新日期。

每周都会附加每个位置的新观察记录。因此,表中的位置有很多次出现。

我想要实现的是能够获得每个位置的最新观察记录。

任何人都可以帮忙吗?

5 个答案:

答案 0 :(得分:3)

 select * from observation where date=(select max(date) from observation)

select top 1 * from observation order by date desc

答案 1 :(得分:1)

select a.* from observations a inner join 
(select locationid ,max(updateddate) dates  from observations
group by locationid) b
on a.locationid=b.locationid
and a.updateddate=b.dates  

答案 2 :(得分:0)

运行查询

select * from Observation 
group by location 
order by viewdate desc

请同时提供有关表格的详细信息以及您想要获得的内容。

编辑:删除了反引号。

答案 3 :(得分:0)

使用[timestamp]数据类型向表中添加一列 执行以下代码:

select top(10) * from yourtablename order by columanname desc

注意:columanname应该是您添加时间戳类型的列

答案 4 :(得分:0)

使用Getdate功能,如下所示。

select * from TBL_MP_QC_CustomerWiseCOA_Master  order by getdate() desc
相关问题