【SQL语句】查询某个表在某时间段中的最新数据

一、思路:首先查询在某个时间段中最新时间的字段,然后用查到的字段与原来的表作自连接,最后对自连接后的表进行所需字段的查询。

二、sql语句:

SELECT
*
FROM
(
SELECT
max(i.createDate) AS createDate,
r.websiteConfigInfo_id AS webId
FROM
run r
WHERE
r.staticsEndTime BETWEEN : beginTime
AND : endTime
AND r.websiteConfigInfo_id = : websiteId
) AS r1
JOIN run r2 ON (
r1.createDate = r2.createDate
AND r1.webId = r2.websiteConfigInfo_id
)

posted @ 2015-03-30 11:53  lusunlufar  阅读(1625)  评论(0编辑  收藏  举报