0

我需要为我的整个表格找到 max(n.LastEdited) (最新编辑日期)并将其写在每一行上。

是)我有的:

SELECT n.ID,
n.Title,
n.News,
(SELECT max(n.LastEdited)) AS NewsLastEdited
FROM News AS n
ORDER BY n.ID DESC
LIMIT 0,20

我得到的(不显示 ID、标题、新闻……):

NewsLastEdited
2012-10-25 10:54:24
2012-10-25 10:54:12
2012-10-25 10:54:02

我想要的是:

NewsLastEdited
2012-10-25 10:54:24
2012-10-25 10:54:24
2012-10-25 10:54:24
4

1 回答 1

1
SELECT  n.*
FROM    news n
        INNER JOIN
        (
            SELECT  ID, Max(LastEdited) lastEdit
            FROM news
            GROUP BY ID
        ) x ON n.ID = x.ID AND 
               n.LastEdited = x.LastEdit
-- WHERE ...
-- ORDER BY ...
-- LIMIT ...
于 2012-10-29T12:36:50.557 回答