我有一张主表人
人字段:Id,AlterationDate
一对多关联中的操作表操作
操作字段:Id,PeopleID,CreationDate
我想查找人中的所有记录,其更改日期晚于人员ID加入的操作中的最新创建日期。
MySQL是方言,日期是DateTime字段。
答案 0 :(得分:1)
select people.* from people
join actions on actions.peopleID = people.id
group by people.id
having max(action.CreationDate) < people.AlterationDate
答案 1 :(得分:0)
试
select p.peopleid
from actions a
inner join people p on p.peopleid = a.peopleid
group by p.peopleid
having max (a.creationdate) < p.alterationdate