[英]MySQL Query: Write max(Date) from whole table to each row
I need to find the max(n.LastEdited) (Latest Editing Date) for my whole table and write it on each row. 我需要找到整个表的max(n.LastEdited)(最新编辑日期)并将其写在每一行上。
What I have: 我有的:
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
What I get (not showing ID, Title, News, ...): 我得到的(不显示ID,标题,新闻等):
NewsLastEdited
2012-10-25 10:54:24
2012-10-25 10:54:12
2012-10-25 10:54:02
What I want: 我想要的是:
NewsLastEdited
2012-10-25 10:54:24
2012-10-25 10:54:24
2012-10-25 10:54:24
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 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.