SELECT t1.id ID,
t1.dispo Disposition,
t1.dt "Date",
max(t1.st) Stamp
FROM docs t1
JOIN (SELECT id, dt, max(dispo) as dispo
FROM docs
GROUP BY id, dt) t2
ON t1.id = t2.id
AND t1.dispo = t2.dispo
AND t1.dt = t2.dt
GROUP BY t1.id, t1.dispo, t1.dt
ORDER BY t1.id, t1.dt;
select q1.id,
q1.dispo,
q1.date,
(select max(stamp) from table_a where id=q1.id and dispo=q1.dispo and date=q1.date) as max_stamp
from (select id, max(dispo) as dispo, date
from table_a
group by id, date) as q1;
而这种方法使用了一个连接...
select q1.id,
q1.dispo,
q1.date,
max(a.stamp) as max_stamp
from (select id, max(dispo) as dispo, date
from table_a
group by id, date) as q1
join table_a a on (a.id=q1.id and a.dispo=q1.dispo as a.date=q1.date)
我已经设置了下一个示例:
首先你需要知道每个日期的 MAX 配置:
然后您可以通过性格和日期获得 MAX Stamp。
dbfiddle在这里
这种方法使用相关子查询来查找最大时间戳...
而这种方法使用了一个连接...