delimiter $
create function get_latest_positionlogid(unitid int)
returns int
begin
declare max_positionlogid int;
declare dt datetime;
select max(positiondatetime) into dt from positionlog where fk_unitid=unitid;
select max(pk_positionlogid) into max_positionlogid from positionlog where fk_unitid=unitid and positiondatetime=dt;
return max_positionlogid;
end;
//写成dt=max(positiondatetime) ,创建报错Not allowed to return a result set from a function