-1

我正在尝试返回带有最新时间戳的注释的任务。尽管此查询有效,但它并没有始终如一地返回最新的时间戳。还有另一种方法可以做到这一点吗?

SELECT DISTINCT  tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note,          max(notes.NoteDate) 
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID 
WHERE notes.NoteDate >= curdate() 
GROUP BY tasks.TaskID
4

1 回答 1

0

尝试以下方式:

SELECT tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note,          notes.NoteDate
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID 
order by NoteDate Desc 
limit 1 

更新,如果您想要多行(例如最后一天的注释):

SELECT tasks.TaskID, tasks.desc, tasks.startdate, tasks.active, notes.note,          notes.NoteDate
FROM tasks INNER JOIN notes ON tasks.TaskID=notes.NoteID 
where notes.NoteDate > date_sub(current_date(),interval 1 day)
order by NoteDate Desc 
于 2013-04-30T16:39:21.027 回答