答案 0 :(得分:1)
由于您有limit
,我会使用subquery
条与PK
一起使用:
select *
from table t
where id = (select t1.id
from table t1
where t1.id_patient = t.id_patient
order by t1.date desc
limit 1
);
但是,如果单个patient
具有多个相同的日期,那么这将只生成基于date
的单个记录。
答案 1 :(得分:0)
SELECT * from rdv a JOIN(SELECT id_patient,MAX(date)date FROM rdv GROUP by id_patient)b on a.id_patient = b.id_patient and a.date = b.date
答案 2 :(得分:0)
如果您想要每位患者的最新记录,那么您不需要聚合。我经常会用相关的子查询来处理它:
select t.*
from t
where t.date = (select max(t2.date) from t t2 where t2.id_patient = t.id_patient);
答案 3 :(得分:-1)
function getCurrentTree(array, names) {
var [name, path] = names.split('.', 2),
result;
array.some(o => {
if (o.name === name) {
return result = path ? getCurrentTree(o.children, path) : o;
}
});
return result
}
var data = [{ name: 'root', children: [{ name: 'page', children: [] }] }];
console.log(getCurrentTree(data, 'root.page'));