的最大日我想從每個WishContent基礎上,wishContent.wishId最新的日期,這樣,如果我有wishContents這樣的:SQL查詢來獲取
ID DATE
#1 : 09-03-2016
#1 : 08-03-2016
#1 : 03-04-2016
#2 : 09-02-2016
#2 : 04-01-2016
然後我只想:
#1 09-03-2016
#2 09-02-2016
SELECT
wish.Status,
wish.Id,
wish.User,
wish.CompletionDate,
wishContent.Content,
wishContent.Title,
wishContent.Country,
wishContent.City,
wishContent.IsAccepted,
wishContent.moderator_Username,
MAX(wishContent.Date) AS max_date
FROM `wish` JOIN wishContent on wish.Id = wishContent.wish_Id
GROUP BY wish.Id where wish.Date
ORDER BY max_date DESC
任何人都可以幫助我嗎?
http://dev.mysql.com/doc/refman/5.7/en/example-maximum-column-group-row .html – CBroe
WHERE通常在GROUP BY之前。 –