SELECT u.Full_Name,
u.Mobile_Number,
l.Latitude,
l.Longitude,
l.LocationSyncDateTime
FROM user AS u
JOIN location AS l ON l.User_Name = u.User_Name
JOIN (SELECT l2.User_Name,
MAX(l2.LocationSyncDateTime) AS LocationSyncDateTime
FROM location AS l2
GROUP BY l2.User_Name
) AS t3 ON t3.User_Name = l.User_Name
AND t3.LocationSyncDateTime = l.LocationSyncDateTime
1条答案
按热度按时间xghobddn1#
获取最大值
LocationSyncDateTime
为了一个User_Name
在派生表中t3
.将主表联接到上的此派生表
User_Name
和最大值LocationSyncDateTime
.请尝试以下操作: