我有 3 个表:p、p2l、l
p - p_id;
p2l - p_id, l_id
l - l_id, date
如何获得每个 p_id 的 max(date)?
这个查询是否正确?
1
SELECT plot_id, max(l.date) as l_maxDate
FROM p2l
LEFT JOIN l ON p2l.l_id = l.l_id
Group by p_id
2
SELECT plot_id, maxDate.maxLDate,
FROM p2l
INNER JOIN
(SELECT l_id, MAX(date) AS maxLDate
FROM l
GROUP BY l_id) maxDate
ON maxDate.l_id = p2l.l_id
GROUP BY p_id