我有一个包含日期的表,但我需要知道每个位置条件为真的最新日期,唯一的问题是一旦我添加了一个名为“notes”的列,它会破坏查询并返回太多行,当前查询是.. .
SELECT
Location,
MAX(date) AS date,
type,
notes
FROM NotesTable a
INNER JOIN Location b on a.LocationID = b.LocationID
INNER JOIN Type c on a.typeid = c.typeid
WHERE typeid <> 8
GROUP BY Location, type, notes
如果我注释掉注释列,那么它可以正常工作,但是一旦我将它添加到分组中,它就会返回比所需更多的行。
已尝试使用子查询,但仍然无法正常工作,下面的子查询
SELECT
r.location,
r.date,
r.type,
t.notes
FROM (SELECT Location, MAX(date), type
FROM NotesTable a INNER JOIN Location b on a.LocationID = b.LocationID
INNER JOIN Type c on a.typeid = c.typeid
WHERE typeid <> 8
GROUP BY location,type
) r
INNER JOIN NotesTable t ON t.date = r.date
有人有其他建议吗?