SELECT h.Id,h.Name,max(h.Stamp),u.email
FROM schema.heating h
inner JOIN schema.users u ON h.unique_id = u.unique_id
where u.email= 'example@example.com'
group by h.Name
我正在尝试使该语句基于与 unique_id 上另一个表的内部连接返回最新时间戳的唯一条目(名称), 但是它不会为每个带有 max(Stamp) 的条目返回最新的时间戳,有人知道我在这里可能出错的地方吗? 我已经尝试了一段时间了。
最佳答案
您可能需要选择与您的选择结果匹配的元组
select *
from schema.heating h
where (h.Name, h.Stamp) in (
SELECT h.Name, max(h.Stamp)
FROM schema.heating h
inner JOIN schema.users u ON h.unique_id = u.unique_id
where u.email= 'example@example.com'
group by h.Name )
关于mysql - SQL 内部加入基于最新时间戳的唯一条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42680497/